@Override public void setValue(Object value) { setLongValue((Long) value); }
@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); }
newCertTemp.getCertificateType().setLongValue(CertificateType.X_509_PUBLIC_KEY);
private static X509PublicKeyCertificate createPkcs11Template(final X509Cert cert, final byte[] keyId, final char[] label) { if (label == null || label.length == 0) { throw new IllegalArgumentException("label must not be null or empty"); } X509PublicKeyCertificate newCertTemp = new X509PublicKeyCertificate(); newCertTemp.getId().setByteArrayValue(keyId); newCertTemp.getLabel().setCharArrayValue(label); newCertTemp.getToken().setBooleanValue(true); newCertTemp.getCertificateType().setLongValue(CertificateType.X_509_PUBLIC_KEY); newCertTemp.getSubject().setByteArrayValue( cert.cert().getSubjectX500Principal().getEncoded()); newCertTemp.getIssuer().setByteArrayValue( cert.cert().getIssuerX500Principal().getEncoded()); newCertTemp.getSerialNumber().setByteArrayValue( cert.cert().getSerialNumber().toByteArray()); newCertTemp.getValue().setByteArrayValue(cert.encodedCert()); return newCertTemp; }
private static void setKeyAttributes(final String label, final long keyType, final P11NewKeyControl control, final PublicKey publicKey, final PrivateKey privateKey) { if (privateKey != null) { privateKey.getToken().setBooleanValue(true); privateKey.getLabel().setCharArrayValue(label.toCharArray()); privateKey.getKeyType().setLongValue(keyType); privateKey.getSign().setBooleanValue(true); privateKey.getPrivate().setBooleanValue(true); privateKey.getSensitive().setBooleanValue(true); privateKey.getExtractable().setBooleanValue(control.isExtractable()); } if (publicKey != null) { publicKey.getToken().setBooleanValue(true); publicKey.getLabel().setCharArrayValue(label.toCharArray()); publicKey.getKeyType().setLongValue(keyType); publicKey.getVerify().setBooleanValue(true); publicKey.getModifiable().setBooleanValue(Boolean.TRUE); } }
template.getKeyType().setLongValue(keyType); template.getSensitive().setBooleanValue(true); template.getExtractable().setBooleanValue(control.isExtractable()); template.getValueLen().setLongValue((long) (keysize / 8));
template.getKeyType().setLongValue(keyType);
template.getValueLen().setLongValue((long) (keysize / 8));