// Path: here-oauth-client/src/main/java/com/here/account/auth/SignatureCalculator.java
// public static final String ELLIPTIC_CURVE_ALGORITHM = "EC";


import com.ning.http.client.FluentStringsMap;
import com.ning.http.client.oauth.ConsumerKey;
import com.ning.http.client.oauth.OAuthSignatureCalculator;
import com.ning.http.client.oauth.RequestToken;
import org.junit.Test;
import java.security.*;
import java.security.spec.*;
import java.util.*;
import static com.here.account.auth.SignatureCalculator.ELLIPTIC_CURVE_ALGORITHM;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
                expectedAuthHeader.equals(authHeader));
    }


    @Test
    public void testSignatureES512WithBaseUrlWithPort(){
        KeyPair pair = generateES512KeyPair();

        final byte[] keyBytes = pair.getPrivate().getEncoded();
        String keyBase64 = Base64.getEncoder().encodeToString(keyBytes);

        SignatureCalculator sc = new SignatureCalculator(consumerKey, keyBase64);
        String signature = sc.calculateSignature(method, baseURLWithPort, timestamp, nonce, SignatureMethod.ES512, params, params);

        String publicKeyBase64 = Base64.getEncoder().encodeToString(pair.getPublic().getEncoded());
        boolean verified = SignatureCalculator.verifySignature(consumerKey, method, baseURLWithPort, timestamp, nonce, SignatureMethod.ES512, params, params, signature, publicKeyBase64);
        assertTrue(verified);
    }

    @Test
    public void testVerifyES512() {
        String cipherText = "testing public key and signature encryption";
        String publicKeyBase64 = "MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQA2GcrZ94UbrYCsJo6sHOCnw4r5t5xSuX0x3LZPlRxA8dXziN1f1z2qUnudmI69JeEeX8JAfuu8kvRx4bjYnTVIasAO9P2V9eWWOxgfzGaC09JGBFN48XgI++9JNuS50DiHtSeSuM2kYTehHhj22Bj5iNlju1j1BbsAc1PS79G2pOpoFs=";
        String signature = "MIGIAkIAz0ZVhsjWnbmdZkBHP7wl5u5q4qN1K5bFgHNRvZeh4lYxpuUg60vncYZLwBM4zHev1F4bSkLqudhtAt8arwrLs1YCQgFQrQXvoSsAfO/gK7IEQXEFK1UGN4RDnVQRpKaZiKDbOCY2qZ3AyGeaydrnoc6o0RdHzeuJaj9Or2YjqE7PjnwvSg==";
        assertTrue(SignatureCalculator.verifySignature(cipherText, SignatureMethod.ES512, signature, publicKeyBase64));
    }

    public static KeyPair generateES512KeyPair()  {
        try {
            ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp521r1");
// Path: here-oauth-client/src/main/java/com/here/account/auth/SignatureCalculator.java
// public static final String ELLIPTIC_CURVE_ALGORITHM = "EC";


// Path: here-oauth-client/src/test/java/com/here/account/auth/SignatureCalculatorTest.java
import com.ning.http.client.FluentStringsMap;
import com.ning.http.client.oauth.ConsumerKey;
import com.ning.http.client.oauth.OAuthSignatureCalculator;
import com.ning.http.client.oauth.RequestToken;
import org.junit.Test;
import java.security.*;
import java.security.spec.*;
import java.util.*;
import static com.here.account.auth.SignatureCalculator.ELLIPTIC_CURVE_ALGORITHM;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

                expectedAuthHeader.equals(authHeader));
    }


    @Test
    public void testSignatureES512WithBaseUrlWithPort(){
        KeyPair pair = generateES512KeyPair();

        final byte[] keyBytes = pair.getPrivate().getEncoded();
        String keyBase64 = Base64.getEncoder().encodeToString(keyBytes);

        SignatureCalculator sc = new SignatureCalculator(consumerKey, keyBase64);
        String signature = sc.calculateSignature(method, baseURLWithPort, timestamp, nonce, SignatureMethod.ES512, params, params);

        String publicKeyBase64 = Base64.getEncoder().encodeToString(pair.getPublic().getEncoded());
        boolean verified = SignatureCalculator.verifySignature(consumerKey, method, baseURLWithPort, timestamp, nonce, SignatureMethod.ES512, params, params, signature, publicKeyBase64);
        assertTrue(verified);
    }

    @Test
    public void testVerifyES512() {
        String cipherText = "testing public key and signature encryption";
        String publicKeyBase64 = "MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQA2GcrZ94UbrYCsJo6sHOCnw4r5t5xSuX0x3LZPlRxA8dXziN1f1z2qUnudmI69JeEeX8JAfuu8kvRx4bjYnTVIasAO9P2V9eWWOxgfzGaC09JGBFN48XgI++9JNuS50DiHtSeSuM2kYTehHhj22Bj5iNlju1j1BbsAc1PS79G2pOpoFs=";
        String signature = "MIGIAkIAz0ZVhsjWnbmdZkBHP7wl5u5q4qN1K5bFgHNRvZeh4lYxpuUg60vncYZLwBM4zHev1F4bSkLqudhtAt8arwrLs1YCQgFQrQXvoSsAfO/gK7IEQXEFK1UGN4RDnVQRpKaZiKDbOCY2qZ3AyGeaydrnoc6o0RdHzeuJaj9Or2YjqE7PjnwvSg==";
        assertTrue(SignatureCalculator.verifySignature(cipherText, SignatureMethod.ES512, signature, publicKeyBase64));
    }

    public static KeyPair generateES512KeyPair()  {
        try {
            ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp521r1");
            KeyPairGenerator kpg = KeyPairGenerator.getInstance(ELLIPTIC_CURVE_ALGORITHM);