/** * The getInstance method of the PrivateKey class uses this method to create * an instance of a PKCS#11 RSA private key. * * @param session * The session to use for reading attributes. This session must * have the appropriate rights; i.e. it must be a user-session, if * it is a private object. * @param objectHandle * The object handle as given from the PKCS#111 module. * @return The object representing the PKCS#11 object. * The returned object can be casted to the * according sub-class. * @exception TokenException * If getting the attributes failed. * @preconditions (session <> null) * @postconditions (result <> null) */ public static PKCS11Object getInstance(Session session, long objectHandle) throws TokenException { return new RSAPrivateKey(session, objectHandle); }
newObject = RSAPrivateKey.getInstance(session, objectHandle); } else if (keyType.equals(Key.KeyType.DSA)) { newObject = DSAPrivateKey.getInstance(session, objectHandle);
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); modulus = new ByteArrayAttribute(Attribute.MODULUS); publicExponent = new ByteArrayAttribute(Attribute.PUBLIC_EXPONENT); privateExponent = new ByteArrayAttribute(Attribute.PRIVATE_EXPONENT); prime1 = new ByteArrayAttribute(Attribute.PRIME_1); prime2 = new ByteArrayAttribute(Attribute.PRIME_2); exponent1 = new ByteArrayAttribute(Attribute.EXPONENT_1); exponent2 = new ByteArrayAttribute(Attribute.EXPONENT_2); coefficient = new ByteArrayAttribute(Attribute.COEFFICIENT); putAttributesInTable(this); }
@Override protected P11Identity generateRSAKeypair0(final int keysize, final BigInteger publicExponent, final String label, P11NewKeyControl control) throws P11TokenException { RSAPrivateKey privateKey = new RSAPrivateKey(); RSAPublicKey publicKey = new RSAPublicKey(); setKeyAttributes(label, PKCS11Constants.CKK_RSA, control, publicKey, privateKey); publicKey.getModulusBits().setLongValue((long) keysize); if (publicExponent != null) { publicKey.getPublicExponent().setByteArrayValue(publicExponent.toByteArray()); } return generateKeyPair(PKCS11Constants.CKM_RSA_PKCS_KEY_PAIR_GEN, privateKey, publicKey); }
@Override protected P11Identity generateRSAKeypair0(int keysize, BigInteger publicExponent, P11NewKeyControl control) throws P11TokenException { long mech = PKCS11Constants.CKM_RSA_PKCS_KEY_PAIR_GEN; assertMechanismSupported(mech); RSAPrivateKey privateKey = new RSAPrivateKey(); RSAPublicKey publicKey = new RSAPublicKey(); setKeyAttributes(control, publicKey, privateKey); publicKey.getModulusBits().setLongValue((long) keysize); if (publicExponent != null) { publicKey.getPublicExponent().setByteArrayValue(publicExponent.toByteArray()); } return generateKeyPair(mech, control.getId(), privateKey, publicKey); }