/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. */ public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient())); }
public int hashCode() { return this.getModulus().hashCode() ^ this.getPublicExponent().hashCode() ^ this.getPrivateExponent().hashCode(); }
@Override public PublicKey publicKeyFromPrivateKey(PrivateKey privateKey, KeyFactory keyFactory) throws InvalidKeySpecException { BCRSAPrivateCrtKey privateCrtKey = (BCRSAPrivateCrtKey) privateKey; RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(privateCrtKey.getModulus(), privateCrtKey.getPublicExponent()); return keyFactory.generatePublic(publicKeySpec); } }
public KeyPair generateKeyPair() { AsymmetricCipherKeyPair pair = engine.generateKeyPair(); RSAKeyParameters pub = (RSAKeyParameters)pair.getPublic(); RSAPrivateCrtKeyParameters priv = (RSAPrivateCrtKeyParameters)pair.getPrivate(); return new KeyPair(new BCRSAPublicKey(pub), new BCRSAPrivateCrtKey(priv)); } }
public String toString() { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); buf.append("RSA Private CRT Key [").append( RSAUtil.generateKeyFingerprint(this.getModulus())).append("]") .append(",[") .append(RSAUtil.generateExponentFingerprint(this.getPublicExponent())) .append("]") .append(nl); buf.append(" modulus: ").append(this.getModulus().toString(16)).append(nl); buf.append(" public exponent: ").append(this.getPublicExponent().toString(16)).append(nl); return buf.toString(); } }
protected Key engineTranslateKey( Key key) throws InvalidKeyException { if (key instanceof RSAPublicKey) { return new BCRSAPublicKey((RSAPublicKey)key); } else if (key instanceof RSAPrivateCrtKey) { return new BCRSAPrivateCrtKey((RSAPrivateCrtKey)key); } else if (key instanceof java.security.interfaces.RSAPrivateKey) { return new BCRSAPrivateKey((java.security.interfaces.RSAPrivateKey)key); } throw new InvalidKeyException("key type unknown"); }
public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof RSAPrivateCrtKey)) { return false; } RSAPrivateCrtKey key = (RSAPrivateCrtKey)o; return this.getModulus().equals(key.getModulus()) && this.getPublicExponent().equals(key.getPublicExponent()) && this.getPrivateExponent().equals(key.getPrivateExponent()) && this.getPrimeP().equals(key.getPrimeP()) && this.getPrimeQ().equals(key.getPrimeQ()) && this.getPrimeExponentP().equals(key.getPrimeExponentP()) && this.getPrimeExponentQ().equals(key.getPrimeExponentQ()) && this.getCrtCoefficient().equals(key.getCrtCoefficient()); }
return new BCRSAPrivateCrtKey( RSAPrivateKey.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded())); return new BCRSAPrivateCrtKey((RSAPrivateCrtKeySpec)keySpec); return new BCRSAPrivateCrtKey((RSAPrivateCrtKeyParameters)parameters);
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (RSAUtil.isRsaOid(algOid)) { RSAPrivateKey rsaPrivKey = RSAPrivateKey.getInstance(keyInfo.parsePrivateKey()); if (rsaPrivKey.getCoefficient().intValue() == 0) { return new BCRSAPrivateKey(rsaPrivKey); } else { return new BCRSAPrivateCrtKey(keyInfo); } } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }