@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); }
if (p11Key instanceof RSAPublicKey) { RSAPublicKey rsaP11Key = (RSAPublicKey) p11Key; byte[] expBytes = rsaP11Key.getPublicExponent().getByteArrayValue(); BigInteger exp = new BigInteger(1, expBytes); byte[] modBytes = rsaP11Key.getModulus().getByteArrayValue(); BigInteger mod = new BigInteger(1, modBytes); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(mod, exp);
/** * The getInstance method of the PublicKey class uses this method to create * an instance of a PKCS#11 RSA public 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 RSAPublicKey(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); modulusBits = new LongAttribute(Attribute.MODULUS_BITS); putAttributesInTable(this); }
newObject = RSAPublicKey.getInstance(session, objectHandle); } else if (keyType.equals(Key.KeyType.DSA)) { newObject = DSAPublicKey.getInstance(session, objectHandle);
if (p11Key instanceof RSAPublicKey) { RSAPublicKey rsaP11Key = (RSAPublicKey) p11Key; byte[] expBytes = rsaP11Key.getPublicExponent().getByteArrayValue(); BigInteger exp = new BigInteger(1, expBytes); byte[] modBytes = rsaP11Key.getModulus().getByteArrayValue(); BigInteger mod = new BigInteger(1, modBytes); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(mod, exp);
@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); }