Search in sources :

Example 1 with ECPublicKeyImpl

use of sun.security.ec.ECPublicKeyImpl in project jdk8u_jdk by JetBrains.

the class ECKeyPairGenerator method generateKeyPair.

// generate the keypair. See JCA doc
@Override
public KeyPair generateKeyPair() {
    byte[] encodedParams = ECUtil.encodeECParameterSpec(null, (ECParameterSpec) params);
    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);
    try {
        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);
        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[]) keyBytes[0]);
        PrivateKey privateKey = new ECPrivateKeyImpl(s, (ECParameterSpec) params);
        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[]) keyBytes[1], ((ECParameterSpec) params).getCurve());
        PublicKey publicKey = new ECPublicKeyImpl(w, (ECParameterSpec) params);
        return new KeyPair(publicKey, privateKey);
    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
Also used : ECPublicKeyImpl(sun.security.ec.ECPublicKeyImpl) ECPrivateKeyImpl(sun.security.ec.ECPrivateKeyImpl) BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint)

Aggregations

BigInteger (java.math.BigInteger)1 ECPoint (java.security.spec.ECPoint)1 ECPrivateKeyImpl (sun.security.ec.ECPrivateKeyImpl)1 ECPublicKeyImpl (sun.security.ec.ECPublicKeyImpl)1