use of sun.security.ec.ECPrivateKeyImpl 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);
}
}
Aggregations