public KeyPair toEC(boolean includePrivateParameters, Provider provider) {

        if (provider == null) {
            // Our default provider for this class
            provider = Security.getProvider("SunEC");
        }

        if (!JsonWebKeyType.EC.equals(kty) && !JsonWebKeyType.EC_HSM.equals(kty)) {
            throw new IllegalArgumentException("Not an EC key.");
        }

        try {
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", provider);

            ECGenParameterSpec gps = new ECGenParameterSpec(CURVE_TO_SPEC_NAME.get(crv));
            kpg.initialize(gps);

            // Generate dummy keypair to get parameter spec.
            KeyPair apair = kpg.generateKeyPair();
            ECPublicKey apub = (ECPublicKey) apair.getPublic();
            ECParameterSpec aspec = apub.getParams();

            ECPoint ecPoint = new ECPoint(new BigInteger(1, x), new BigInteger(1, y));

            KeyPair realKeyPair;

            if (includePrivateParameters) {
                realKeyPair = new KeyPair(getECPublicKey(ecPoint, aspec, provider),
                        getECPrivateKey(d, aspec, provider));
            } else {
                realKeyPair = new KeyPair(getECPublicKey(ecPoint, aspec, provider), null);
            }

            return realKeyPair;
        } catch (GeneralSecurityException e) {
            throw new IllegalStateException(e);
        }
    }
public KeyPair toEC ( boolean includePrivateParameters , Provider provider ) { if ( provider == null ) { provider = Security . getProvider ( "SunEC" ) ; } if ( ! JsonWebKeyType . EC . equals ( kty ) && ! JsonWebKeyType . EC_HSM . equals ( kty ) ) { throw new IllegalArgumentException ( "Not an EC key." ) ; } try { KeyPairGenerator kpg = KeyPairGenerator . getInstance ( "EC" , provider ) ; ECGenParameterSpec gps = new ECGenParameterSpec ( CURVE_TO_SPEC_NAME . get ( crv ) ) ; kpg . initialize ( gps ) ; KeyPair apair = kpg . generateKeyPair ( ) ; ECPublicKey apub = ( ECPublicKey ) apair . getPublic ( ) ; ECParameterSpec aspec = apub . getParams ( ) ; ECPoint ecPoint = new ECPoint ( new BigInteger ( 1 , x ) , new BigInteger ( 1 , y ) ) ; KeyPair realKeyPair ; if ( includePrivateParameters ) { realKeyPair = new KeyPair ( getECPublicKey ( ecPoint , aspec , provider ) , getECPrivateKey ( d , aspec , provider ) ) ; } else { realKeyPair = new KeyPair ( getECPublicKey ( ecPoint , aspec , provider ) , null ) ; } return realKeyPair ; } catch ( GeneralSecurityException e ) { throw new IllegalStateException ( e ) ; } }
Converts JSON web key to EC key pair and include the private key if set to
true.

@param includePrivateParameters
true if the EC key pair should include the private key. False
otherwise.
@param provider
Java security provider
@return EC key pair