List of usage examples for org.bouncycastle.asn1.x9 X9ECParameters getEncoded
public byte[] getEncoded() throws IOException
From source file:org.xipki.commons.security.pkcs11.iaik.IaikP11Slot.java
License:Open Source License
@Override protected P11Identity doGenerateECKeypair(final ASN1ObjectIdentifier curveId, final String label) throws P11TokenException { ECDSAPrivateKey privateKey = new ECDSAPrivateKey(); ECDSAPublicKey publicKey = new ECDSAPublicKey(); setKeyAttributes(label, P11Constants.CKK_EC, publicKey, privateKey); byte[] encodedCurveId; try {/*from ww w. j a v a2s.c om*/ encodedCurveId = curveId.getEncoded(); } catch (IOException ex) { throw new P11TokenException(ex.getMessage(), ex); } try { publicKey.getEcdsaParams().setByteArrayValue(encodedCurveId); return generateKeyPair(P11Constants.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(P11Constants.CKM_EC_KEY_PAIR_GEN, privateKey, publicKey); } }
From source file:org.xipki.security.p11.iaik.IaikP11Slot.java
License:Open Source License
private KeyPair generateSpecifiedECDSAKeyPair(final Session session, final ASN1ObjectIdentifier curveId, final X9ECParameters ecParams, final byte[] id, String label) throws TokenException, IOException { ECDSAPrivateKey privateKeyTemplate = new ECDSAPrivateKey(); ECDSAPublicKey publicKeyTemplate = new ECDSAPublicKey(); setKeyAttributes(id, label, PKCS11Constants.CKK_ECDSA, privateKeyTemplate, publicKeyTemplate); byte[] ecdsaParamsBytes = ecParams.getEncoded(); publicKeyTemplate.getEcdsaParams().setByteArrayValue(ecdsaParamsBytes); return session.generateKeyPair(Mechanism.get(PKCS11Constants.CKM_EC_KEY_PAIR_GEN), publicKeyTemplate, privateKeyTemplate);/*from w ww . j a va 2 s. c o m*/ }