sb.append(" (").append("id: ").append(objectId.idHex()).append(")\n"); P11Identity identity = identities.get(objectId); if (identity.publicKey() != null) { String algo = identity.publicKey().getAlgorithm(); sb.append("\t\tAlgorithm: ").append(algo).append("\n"); X509Certificate[] certs = identity.certificateChain();
public static P11RSAKeyParameter getInstance(final P11CryptService p11CryptService, final P11EntityIdentifier identityId) throws InvalidKeyException { ParamUtil.requireNonNull("p11CryptService", p11CryptService); ParamUtil.requireNonNull("identityId", identityId); RSAPublicKey key; try { key = (RSAPublicKey) p11CryptService.getIdentity(identityId).publicKey(); } catch (P11TokenException ex) { throw new InvalidKeyException(ex.getMessage(), ex); } BigInteger modulus = key.getModulus(); BigInteger publicExponent = key.getPublicExponent(); return new P11RSAKeyParameter(p11CryptService, identityId, modulus, publicExponent); }
@Override public void updateCertificate(final P11ObjectIdentifier objectId, final X509Certificate newCert) throws P11TokenException, CertificateException { ParamUtil.requireNonNull("objectId", objectId); ParamUtil.requireNonNull("newCert", newCert); assertWritable("updateCertificate"); P11Identity identity = identities.get(objectId); if (identity == null) { throw new P11UnknownEntityException("could not find private key " + objectId); } java.security.PublicKey pk = identity.publicKey(); java.security.PublicKey newPk = newCert.getPublicKey(); if (!pk.equals(newPk)) { throw new P11TokenException("the given certificate is not for the key " + objectId); } updateCertificate0(objectId, newCert); identity.setCertificates(new X509Certificate[]{newCert}); updateCaCertsOfIdentities(); LOG.info("updated certificate {}", objectId); }
X509Certificate signerCertInP11 = identity.certificate(); PublicKey publicKeyInP11 = (signerCertInP11 != null) ? signerCertInP11.getPublicKey() : identity.publicKey();
public P11PrivateKey(final P11CryptService p11CryptService, final P11EntityIdentifier identityId) throws P11TokenException { this.p11CryptService = ParamUtil.requireNonNull("identityId", p11CryptService); this.identityId = ParamUtil.requireNonNull("entityId", identityId); PublicKey publicKey = p11CryptService.getIdentity(identityId).publicKey(); if (publicKey instanceof RSAPublicKey) { algorithm = "RSA"; keysize = ((RSAPublicKey) publicKey).getModulus().bitLength(); } else if (publicKey instanceof DSAPublicKey) { algorithm = "DSA"; keysize = ((DSAPublicKey) publicKey).getParams().getP().bitLength(); } else if (publicKey instanceof ECPublicKey) { algorithm = "EC"; keysize = ((ECPublicKey) publicKey).getParams().getCurve().getField().getFieldSize(); } else { throw new P11TokenException("unknown public key: " + publicKey); } }
signatureAlgId = AlgorithmUtil.getSigAlgId(null, conf); } else { PublicKey pubKey = slot.getIdentity(p11ObjId).publicKey(); signatureAlgId = AlgorithmUtil.getSigAlgId(pubKey, conf);
RSAPublicKey rsaPubKey = (RSAPublicKey) cryptService.getIdentity(identityId).publicKey(); this.modulusBitLen = rsaPubKey.getModulus().bitLength();