Fetch public key.

@param service the service
@return the string
@throws Exception the exception
329205
@ReadOperation(produces = MediaType.TEXT_PLAIN_VALUE)
    public String fetchPublicKey(@Nullable final String service) throws Exception {
        val factory = KeyFactory.getInstance("RSA");
        var signingKey = tokenCipherExecutor.getSigningKey();

        if (StringUtils.isNotBlank(service)) {
            val registeredService = this.servicesManager.findServiceBy(service);
            RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(registeredService);
            val serviceCipher = new RegisteredServiceJwtTicketCipherExecutor();
            if (serviceCipher.supports(registeredService)) {
                val cipher = serviceCipher.getTokenTicketCipherExecutorForService(registeredService);
                if (cipher.isEnabled()) {
                    signingKey = cipher.getSigningKey();
                }
            }
        }

        if (signingKey instanceof RSAPrivateCrtKey) {
            val rsaSigningKey = (RSAPrivateCrtKey) signingKey;
            val publicKey = factory.generatePublic(new RSAPublicKeySpec(rsaSigningKey.getModulus(), rsaSigningKey.getPublicExponent()));
            return EncodingUtils.encodeBase64(publicKey.getEncoded());
        }
        return null;
    }
249382
public static systemparameter get(nitro_service service) throws Exception{
		systemparameter obj = new systemparameter();
		systemparameter[] response = (systemparameter[])obj.get_resources(service);
		return response[0];
	}
1187996
public PublicKey get(KeyStoreChooser keyStoreChooser, PublicKeyChooserByAlias publicKeyChooserByAlias) {
        CacheKey cacheKey = new CacheKey(keyStoreChooser.getKeyStoreName(), publicKeyChooserByAlias.getAlias());
        PublicKey retrievedPublicKey = cache.get(cacheKey);

        if (retrievedPublicKey != null) {
            return retrievedPublicKey;
        }

        KeyStore keyStore = keyStoreRegistry.get(keyStoreChooser);

        if (keyStore != null) {
            PublicKeyFactoryBean factory = new PublicKeyFactoryBean();
            factory.setKeystore(keyStore);
            factory.setAlias(publicKeyChooserByAlias.getAlias());
            try {
                factory.afterPropertiesSet();
                PublicKey publicKey = (PublicKey) factory.getObject();

                if (publicKey != null) {
                    cache.put(cacheKey, publicKey);
                }
                return publicKey;
            } catch (Exception e) {
                throw new PublicKeyException("error initializing the public key factory bean", e);
            }
        }

        return null;
    }
256186
public static service get(nitro_service service, String name) throws Exception{
		service obj = new service();
		obj.set_name(name);
		service response = (service) obj.get_resource(service);
		return response;
	}
556431
public OvhSshKeyDetail project_serviceName_sshkey_keyId_GET(String serviceName, String keyId) throws IOException {
		String qPath = "/cloud/project/{serviceName}/sshkey/{keyId}";
		StringBuilder sb = path(qPath, serviceName, keyId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhSshKeyDetail.class);
	}
200535
@SuppressWarnings("WeakerAccess")
    public PublicKey getPublicKey() throws InvalidPublicKeyException {
        if (!PUBLIC_KEY_ALGORITHM.equalsIgnoreCase(type)) {
            throw new InvalidPublicKeyException("The key is not of type RSA", null);
        }
        try {
            KeyFactory kf = KeyFactory.getInstance(PUBLIC_KEY_ALGORITHM);
            BigInteger modulus = new BigInteger(1, Base64.decodeBase64(stringValue("n")));
            BigInteger exponent = new BigInteger(1, Base64.decodeBase64(stringValue("e")));
            return kf.generatePublic(new RSAPublicKeySpec(modulus, exponent));
        } catch (InvalidKeySpecException e) {
            throw new InvalidPublicKeyException("Invalid public key", e);
        } catch (NoSuchAlgorithmException e) {
            throw new InvalidPublicKeyException("Invalid algorithm to generate key", e);
        }
    }
120665
@Override
    public String get(final String key) {
        return retrieve(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return configuration.getString(key);
            }
        }, null);
    }
1342267
private PublicKey getRSAPublicKey(Provider provider) {

        try {
            RSAPublicKeySpec publicKeySpec = getRSAPublicKeySpec();
            KeyFactory factory = provider != null ? KeyFactory.getInstance("RSA", provider)
                    : KeyFactory.getInstance("RSA");

            return factory.generatePublic(publicKeySpec);
        } catch (GeneralSecurityException e) {
            throw new IllegalStateException(e);
        }
    }
748896
public static String buildRegisteredServiceCacheKey(final SamlRegisteredService service) {
        val key = service.getMetadataLocation();
        LOGGER.trace("Determined cache key for service [{}] as [{}]", service.getName(), key);
        val hashedKey = DigestUtils.sha512(key);
        LOGGER.trace("Hashed service cache key as [{}]", hashedKey);
        return hashedKey;
    }
1087141
public static dnsparameter get(nitro_service service) throws Exception{
		dnsparameter obj = new dnsparameter();
		dnsparameter[] response = (dnsparameter[])obj.get_resources(service);
		return response[0];
	}
779003
public static Credential getServiceAccountCredential(String serviceAccountId,
      String privateKeyFile) throws GeneralSecurityException, IOException {
    return getServiceAccountCredential(serviceAccountId, privateKeyFile, DatastoreOptions.SCOPES);
  }
74371
protected String getSigningHashAlgorithm(final OidcRegisteredService service) {
        val alg = getConfigurationContext().getIdTokenSigningAndEncryptionService().getJsonWebKeySigningAlgorithm(service);
        LOGGER.debug("Signing algorithm specified by service [{}] is [{}]", service.getServiceId(), alg);

        if (AlgorithmIdentifiers.RSA_USING_SHA512.equalsIgnoreCase(alg)) {
            return MessageDigestAlgorithms.SHA_512;
        }
        if (AlgorithmIdentifiers.RSA_USING_SHA384.equalsIgnoreCase(alg)) {
            return MessageDigestAlgorithms.SHA_384;
        }
        if (AlgorithmIdentifiers.RSA_USING_SHA256.equalsIgnoreCase(alg)) {
            return MessageDigestAlgorithms.SHA_256;
        }
        throw new IllegalArgumentException("Could not determine the hash algorithm for the id token issued to service " + service.getServiceId());
    }
1337402
public static service[] get(nitro_service service) throws Exception{
		service obj = new service();
		service[] response = (service[])obj.get_resources(service);
		return response;
	}
1356786
public static sslparameter get(nitro_service service) throws Exception{
		sslparameter obj = new sslparameter();
		sslparameter[] response = (sslparameter[])obj.get_resources(service);
		return response[0];
	}
536386
public static PublicKey decodePublicKey(String pemEncoded) throws Exception {
        pemEncoded = removeBeginEnd(pemEncoded);
        byte[] encodedBytes = Base64.getDecoder().decode(pemEncoded);

        X509EncodedKeySpec spec = new X509EncodedKeySpec(encodedBytes);
        KeyFactory kf = KeyFactory.getInstance("RSA");
        return kf.generatePublic(spec);
    }
172589
public static Optional<JsonWebKeySet> getJsonWebKeySet(final OidcRegisteredService service) {
        try {
            LOGGER.trace("Loading JSON web key from [{}]", service.getJwks());

            val resource = getJsonWebKeySetResource(service);
            val jsonWebKeySet = buildJsonWebKeySet(resource);

            if (jsonWebKeySet == null || jsonWebKeySet.getJsonWebKeys().isEmpty()) {
                LOGGER.warn("No JSON web keys could be found for [{}]", service);
                return Optional.empty();
            }

            val badKeysCount = jsonWebKeySet.getJsonWebKeys().stream().filter(k ->
                StringUtils.isBlank(k.getAlgorithm())
                    && StringUtils.isBlank(k.getKeyId())
                    && StringUtils.isBlank(k.getKeyType())).count();

            if (badKeysCount == jsonWebKeySet.getJsonWebKeys().size()) {
                LOGGER.warn("No valid JSON web keys could be found for [{}]", service);
                return Optional.empty();
            }

            val webKey = getJsonWebKeyFromJsonWebKeySet(jsonWebKeySet);
            if (Objects.requireNonNull(webKey).getPublicKey() == null) {
                LOGGER.warn("JSON web key retrieved [{}] has no associated public key", webKey.getKeyId());
                return Optional.empty();
            }
            return Optional.of(jsonWebKeySet);

        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }

        return Optional.empty();
    }
492839
public static csparameter get(nitro_service service) throws Exception{
		csparameter obj = new csparameter();
		csparameter[] response = (csparameter[])obj.get_resources(service);
		return response[0];
	}