class SecurityUtils {

    public static String readSecret(HttpsConfig config) {
        if (config.getKeyStore() != null) {
            try {
                Key key = loadKey(config);
                if (key == null) {
                    throw new UnrecoverableKeyException(String.format(
                        "No key with private key entry could be used in the keystore. Provided key alias: %s",
                        config.getKeyAlias() == null ? "<not provided>" : config.getKeyAlias()));
                }
                return Base64.getEncoder().encodeToString(key.getEncoded());
            } catch (UnrecoverableKeyException e) {
                apimlLog.log("org.zowe.apiml.common.errorReadingSecretKey", e.getMessage());
                throw new HttpsConfigError("Error reading secret key: " + e.getMessage(), e,
                    HttpsConfigError.ErrorCode.HTTP_CLIENT_INITIALIZATION_FAILED, config);
            }
        }
        return null;
    }

}