// Path: here-oauth-client/src/main/java/com/here/account/util/OAuthConstants.java
// public class OAuthConstants {
//     
//     /**
//      * We commonly use "UTF-8" charset, this String is its name.
//      */
//     public static final String UTF_8_STRING = "UTF-8";
//     
//     /**
//      * This is the constant for the "UTF-8" Charset already loaded.
//      */
//     public static final Charset UTF_8_CHARSET = Charset.forName(UTF_8_STRING);
// }


import static com.here.account.auth.SignatureMethod.ES512;
import com.here.account.util.OAuthConstants;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
     * @param algorithm elliptic curve algorithm to be used.
     * @return signed cipher text
     */
    private static String computeECDSASignature(byte[] bytesToSign, String key, String algorithm) {
        try {
            Signature s = Signature.getInstance(algorithm);
            s.initSign(consumerSecretToEllipticCurvePrivateKey(key));
            s.update(bytesToSign);
            return Base64.getEncoder().encodeToString(s.sign());
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    /**
     * Compute HMAC digital signature
     * @param bytesToSign bytes to be signed
     * @param algorithm HMAC algorithm to be used.
     * @return signed cipher text
     */
    private static String computeHMACSignature(byte[] bytesToSign, String key, String algorithm) {
        try {
            byte[] keyBytes = (urlEncode(key) + "&").getBytes(OAuthConstants.UTF_8_CHARSET);
            SecretKeySpec signingKey = new SecretKeySpec(keyBytes, algorithm);

            //generate signature based on the requested signature method
            Mac mac = Mac.getInstance(algorithm);
            mac.init(signingKey);
            byte[] signedBytes = mac.doFinal(bytesToSign);
            return Base64.getEncoder().encodeToString(signedBytes);
// Path: here-oauth-client/src/main/java/com/here/account/util/OAuthConstants.java
// public class OAuthConstants {
//     
//     /**
//      * We commonly use "UTF-8" charset, this String is its name.
//      */
//     public static final String UTF_8_STRING = "UTF-8";
//     
//     /**
//      * This is the constant for the "UTF-8" Charset already loaded.
//      */
//     public static final Charset UTF_8_CHARSET = Charset.forName(UTF_8_STRING);
// }


// Path: here-oauth-client/src/main/java/com/here/account/auth/SignatureCalculator.java
import static com.here.account.auth.SignatureMethod.ES512;
import com.here.account.util.OAuthConstants;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

     * @param algorithm elliptic curve algorithm to be used.
     * @return signed cipher text
     */
    private static String computeECDSASignature(byte[] bytesToSign, String key, String algorithm) {
        try {
            Signature s = Signature.getInstance(algorithm);
            s.initSign(consumerSecretToEllipticCurvePrivateKey(key));
            s.update(bytesToSign);
            return Base64.getEncoder().encodeToString(s.sign());
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    /**
     * Compute HMAC digital signature
     * @param bytesToSign bytes to be signed
     * @param algorithm HMAC algorithm to be used.
     * @return signed cipher text
     */
    private static String computeHMACSignature(byte[] bytesToSign, String key, String algorithm) {
        try {
            byte[] keyBytes = (urlEncode(key) + "&").getBytes(OAuthConstants.UTF_8_CHARSET);
            SecretKeySpec signingKey = new SecretKeySpec(keyBytes, algorithm);

            //generate signature based on the requested signature method
            Mac mac = Mac.getInstance(algorithm);
            mac.init(signingKey);
            byte[] signedBytes = mac.doFinal(bytesToSign);
            return Base64.getEncoder().encodeToString(signedBytes);
        } catch (Exception e) {