private void setupContentDigest() { if (isRaw) { this.contentDigest = new NullPssDigest(mgfDigest); } else { this.contentDigest = mgfDigest; } }
BCRSAPublicKey( SubjectPublicKeyInfo info) { populateFromPublicKeyInfo(info); }
/** * Generates a RSA key pair. * * @param random Random source required for key generation. * @param bitLength Desired key size in bits. * * @return RSA key pair of desired size. */ public static KeyPair generateRSA(final SecureRandom random, final int bitLength) { final org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyPairGeneratorSpi generator = new org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyPairGeneratorSpi(); generator.initialize(bitLength, random); return generator.generateKeyPair(); }
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(); }
public int hashCode() { return this.getModulus().hashCode() ^ this.getPublicExponent().hashCode() ^ this.getPrivateExponent().hashCode(); }
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 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 int hashCode() { return getModulus().hashCode() ^ getPrivateExponent().hashCode(); }
public int hashCode() { return this.getModulus().hashCode() ^ this.getPublicExponent().hashCode(); }
public String toString() { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); buf.append("RSA Private Key [").append( RSAUtil.generateKeyFingerprint(this.getModulus())).append("],[]").append(nl); buf.append(" modulus: ").append(this.getModulus().toString(16)).append(nl); return buf.toString(); } }
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)); } }
protected void engineInitVerify( PublicKey publicKey) throws InvalidKeyException { if (!(publicKey instanceof RSAPublicKey)) { throw new InvalidKeyException("Supplied key (" + getType(publicKey) + ") is not a RSAPublicKey instance"); } CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey); digest.reset(); cipher.init(false, param); }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { if (!(privateKey instanceof RSAPrivateKey)) { throw new InvalidKeyException("Supplied key (" + getType(privateKey) + ") is not a RSAPrivateKey instance"); } CipherParameters param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey); digest.reset(); cipher.init(true, param); }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey); signer.init(true, param); }
protected void engineInitVerify( PublicKey publicKey) throws InvalidKeyException { CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey); signer.init(false, param); }
protected AlgorithmParameterSpec engineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == null) { throw new NullPointerException("argument to getParameterSpec must not be null"); } return localEngineGetParameterSpec(paramSpec); }
protected byte[] engineGetEncoded( String format) { if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509")) { return engineGetEncoded(); } return null; }
protected byte[] engineGetEncoded( String format) throws IOException { if (format.equalsIgnoreCase("X.509") || format.equalsIgnoreCase("ASN.1")) { return engineGetEncoded(); } return null; }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey); signer.init(true, param); }
protected void engineInitVerify( PublicKey publicKey) throws InvalidKeyException { CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey); signer.init(false, param); }