// Path: httpsig/callout/src/main/java/com/google/apigee/callout/httpsignature/KeyUtils.java
// public static class KeyParseException extends Exception {
// 
//     private static final long serialVersionUID = 0L;
// 
//     KeyParseException(String message) {
//         super(message);
//     }
// 
//     KeyParseException(String message, Throwable th) {
//         super(message, th);
//     }
// }


import com.apigee.flow.message.MessageContext;
import com.google.apigee.callout.httpsignature.KeyUtils.KeyParseException;
import com.google.common.io.BaseEncoding;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;
import java.util.Optional;
    String keyEncoding = (String) properties.get("secret-key-encoding");
    if (keyEncoding == null || keyEncoding.equals("")) {
      return encodedKey.getBytes(StandardCharsets.UTF_8);
    }
    keyEncoding = PackageUtils.resolvePropertyValue(keyEncoding, c);
    if (keyEncoding == null || keyEncoding.equals("")) {
      return encodedKey.getBytes(StandardCharsets.UTF_8);
    }

    final Optional<SecretKeyEncoding> parsedEncoding =
        SecretKeyEncoding.getValueOf(keyEncoding.toUpperCase());

    if (parsedEncoding.isPresent()) {
      switch (parsedEncoding.get()) {
        case HEX:
        case BASE16:
          return BaseEncoding.base16()
              .lowerCase()
              .decode(encodedKey.replaceAll("\\s", "").toLowerCase());
        case BASE64:
          return BaseEncoding.base64().decode(encodedKey);
        case BASE64URL:
          return BaseEncoding.base64Url().decode(encodedKey);
      }
    }
    return encodedKey.getBytes(StandardCharsets.UTF_8);
  }

  public PublicKey getPublicKey()
      throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, CertificateException,
// Path: httpsig/callout/src/main/java/com/google/apigee/callout/httpsignature/KeyUtils.java
// public static class KeyParseException extends Exception {
// 
//     private static final long serialVersionUID = 0L;
// 
//     KeyParseException(String message) {
//         super(message);
//     }
// 
//     KeyParseException(String message, Throwable th) {
//         super(message, th);
//     }
// }


// Path: httpsig/callout/src/main/java/com/google/apigee/callout/httpsignature/KeyProviderImpl.java
import com.apigee.flow.message.MessageContext;
import com.google.apigee.callout.httpsignature.KeyUtils.KeyParseException;
import com.google.common.io.BaseEncoding;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;
import java.util.Optional;

    String keyEncoding = (String) properties.get("secret-key-encoding");
    if (keyEncoding == null || keyEncoding.equals("")) {
      return encodedKey.getBytes(StandardCharsets.UTF_8);
    }
    keyEncoding = PackageUtils.resolvePropertyValue(keyEncoding, c);
    if (keyEncoding == null || keyEncoding.equals("")) {
      return encodedKey.getBytes(StandardCharsets.UTF_8);
    }

    final Optional<SecretKeyEncoding> parsedEncoding =
        SecretKeyEncoding.getValueOf(keyEncoding.toUpperCase());

    if (parsedEncoding.isPresent()) {
      switch (parsedEncoding.get()) {
        case HEX:
        case BASE16:
          return BaseEncoding.base16()
              .lowerCase()
              .decode(encodedKey.replaceAll("\\s", "").toLowerCase());
        case BASE64:
          return BaseEncoding.base64().decode(encodedKey);
        case BASE64URL:
          return BaseEncoding.base64Url().decode(encodedKey);
      }
    }
    return encodedKey.getBytes(StandardCharsets.UTF_8);
  }

  public PublicKey getPublicKey()
      throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, CertificateException,
          KeyParseException {