public int hashCode() { return this.getModulus().hashCode() ^ this.getPublicExponent().hashCode(); }
BCRSAPublicKey( SubjectPublicKeyInfo info) { populateFromPublicKeyInfo(info); }
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 PublicKey generatePublic(SubjectPublicKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm(); if (RSAUtil.isRsaOid(algOid)) { return new BCRSAPublicKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } } }
public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof RSAPublicKey)) { return false; } RSAPublicKey key = (RSAPublicKey)o; return getModulus().equals(key.getModulus()) && getPublicExponent().equals(key.getPublicExponent()); }
protected PublicKey engineGeneratePublic( KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof RSAPublicKeySpec) { return new BCRSAPublicKey((RSAPublicKeySpec)keySpec); } else if (keySpec instanceof OpenSSHPublicKeySpec) { CipherParameters parameters = OpenSSHPublicKeyUtil.parsePublicKey(((OpenSSHPublicKeySpec)keySpec).getEncoded()); if (parameters instanceof RSAKeyParameters) { return new BCRSAPublicKey((RSAKeyParameters)parameters); } throw new InvalidKeySpecException("Open SSH public key is not RSA public key"); } return super.engineGeneratePublic(keySpec); }
public String toString() { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); buf.append("RSA Public 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 byte[] getEncoded() { return KeyUtil.getEncodedSubjectPublicKeyInfo(algorithmIdentifier, new org.bouncycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent())); }