@Override
protected P11Identity generateECKeypair0(final ASN1ObjectIdentifier curveId,
final String label, P11NewKeyControl control) throws P11TokenException {
ECDSAPrivateKey privateKey = new ECDSAPrivateKey();
ECDSAPublicKey publicKey = new ECDSAPublicKey();
setKeyAttributes(label, PKCS11Constants.CKK_EC, control, publicKey, privateKey);
byte[] encodedCurveId;
try {
encodedCurveId = curveId.getEncoded();
} catch (IOException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
try {
publicKey.getEcdsaParams().setByteArrayValue(encodedCurveId);
return generateKeyPair(PKCS11Constants.CKM_EC_KEY_PAIR_GEN, privateKey, publicKey);
} catch (P11TokenException ex) {
X9ECParameters ecParams = ECNamedCurveTable.getByOID(curveId);
if (ecParams == null) {
throw new IllegalArgumentException("could not get X9ECParameters for curve "
+ curveId.getId());
}
try {
publicKey.getEcdsaParams().setByteArrayValue(ecParams.getEncoded());
} catch (IOException ex2) {
throw new P11TokenException(ex.getMessage(), ex);
}
return generateKeyPair(PKCS11Constants.CKM_EC_KEY_PAIR_GEN, privateKey, publicKey);
}
}