Search in sources :

Example 1 with ECPrivateKey

use of iaik.pkcs.pkcs11.objects.ECPrivateKey in project xipki by xipki.

the class IaikP11Slot method generateECKeypair0.

@Override
protected P11Identity generateECKeypair0(ASN1ObjectIdentifier curveId, String label, P11NewKeyControl control) throws P11TokenException {
    long mech = PKCS11Constants.CKM_EC_KEY_PAIR_GEN;
    assertMechanismSupported(mech);
    ECPrivateKey privateKey = new ECPrivateKey();
    ECPublicKey publicKey = new ECPublicKey();
    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(mech, 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(mech, privateKey, publicKey);
    }
}
Also used : ECPrivateKey(iaik.pkcs.pkcs11.objects.ECPrivateKey) ECPublicKey(iaik.pkcs.pkcs11.objects.ECPublicKey) X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters) P11TokenException(org.xipki.security.exception.P11TokenException) IOException(java.io.IOException)

Aggregations

ECPrivateKey (iaik.pkcs.pkcs11.objects.ECPrivateKey)1 ECPublicKey (iaik.pkcs.pkcs11.objects.ECPublicKey)1 IOException (java.io.IOException)1 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)1 P11TokenException (org.xipki.security.exception.P11TokenException)1