These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 RSAPublicKeySpec class.
import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.DERObjectIdentifier; import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; // BEGIN android-removed // import org.bouncycastle.jce.interfaces.ElGamalPrivateKey; // import org.bouncycastle.jce.interfaces.ElGamalPublicKey; // import org.bouncycastle.jce.spec.ElGamalPrivateKeySpec; // import org.bouncycastle.jce.spec.ElGamalPublicKeySpec; // import org.bouncycastle.jce.spec.GOST3410PrivateKeySpec; // import org.bouncycastle.jce.spec.GOST3410PublicKeySpec; // END android-removed public abstract class JDKKeyFactory extends KeyFactorySpi
RSAPublicKey rsaKey = (RSAPublicKey) key; if (RSAPublicKeySpec.class.equals(keySpec)) { BigInteger modulus = rsaKey.getModulus(); BigInteger publicExponent = rsaKey.getPublicExponent(); return (T) new RSAPublicKeySpec(modulus, publicExponent); } else if (X509EncodedKeySpec.class.equals(keySpec)) { return (T) new X509EncodedKeySpec(key.getEncoded()); } else { throw new InvalidKeySpecException("Must be RSAPublicKeySpec or X509EncodedKeySpec"); } } else if (key instanceof RSAPrivateCrtKey) { RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key; if (RSAPrivateKeySpec.class.equals(keySpec)) { BigInteger modulus = rsaKey.getModulus(); BigInteger privateExponent = rsaKey.getPrivateExponent(); return (T) new RSAPrivateKeySpec(modulus, privateExponent); } else if (RSAPrivateCrtKeySpec.class.equals(keySpec)) { BigInteger modulus = rsaKey.getModulus();
/** * @return true if the keypairs match */ public static boolean privateKeyMatchesPublicKey(RSAPrivateCrtKeySpec privateKey, RSAPublicKeySpec publicKey) { return privateKey.getPublicExponent().equals(publicKey.getPublicExponent()) && privateKey.getModulus().equals(publicKey.getModulus()); } /** * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return fingerprint(privateKey.getPublicExponent(), privateKey.getModulus()).equals(fingerprint); } /** * @param privateKeyPEM * RSA private key in PEM format * @param fingerprint
} JCERSAPublicKey( RSAPublicKeySpec spec) { this.modulus = spec.getModulus(); this.publicExponent = spec.getPublicExponent(); } JCERSAPublicKey( RSAPublicKey key) { this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); } JCERSAPublicKey( SubjectPublicKeyInfo info) { try
if (spec.isAssignableFrom(RSAPublicKeySpec.class) && key instanceof RSAPublicKey) { RSAPublicKey k = (RSAPublicKey)key; return new RSAPublicKeySpec(k.getModulus(), k.getPublicExponent()); } else if (spec.isAssignableFrom(RSAPrivateKeySpec.class) && key instanceof java.security.interfaces.RSAPrivateKey) { java.security.interfaces.RSAPrivateKey k = (java.security.interfaces.RSAPrivateKey)key; return new RSAPrivateKeySpec(k.getModulus(), k.getPrivateExponent()); } else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey) { RSAPrivateCrtKey k = (RSAPrivateCrtKey)key; return new RSAPrivateCrtKeySpec( k.getModulus(), k.getPublicExponent(), k.getPrivateExponent(), k.getPrimeP(), k.getPrimeQ(),
int exponentLength = readInt(keyByteArray, modulusLength + 4); byte[] exponentByteArray = new byte[exponentLength]; System.arraycopy(keyByteArray, modulusLength + 8, exponentByteArray, 0, exponentLength); BigInteger publicExponent = new BigInteger(1, exponentByteArray); return KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, publicExponent)); } /** * Encrypts given string with Google Public Key. * */ public static String encryptString(String str2Encrypt) throws Exception { byte[] keyByteArray = Base64.decode(GOOGLE_PUBLIC_KEY, Base64.DEFAULT); byte[] header = new byte[5]; byte[] digest = MessageDigest.getInstance("SHA-1").digest(keyByteArray); header[0] = 0; System.arraycopy(digest, 0, header, 1, 4);
BCRSAPublicKey( RSAPublicKeySpec spec) { this.algorithmIdentifier = DEFAULT_ALGORITHM_IDENTIFIER; this.modulus = spec.getModulus(); this.publicExponent = spec.getPublicExponent(); } BCRSAPublicKey( RSAPublicKey key) { this.algorithmIdentifier = DEFAULT_ALGORITHM_IDENTIFIER; this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); } BCRSAPublicKey( SubjectPublicKeyInfo info) {
} JCERSAPublicKey( RSAPublicKeySpec spec) { this.modulus = spec.getModulus(); this.publicExponent = spec.getPublicExponent(); } JCERSAPublicKey( RSAPublicKey key) { this.modulus = key.getModulus(); this.publicExponent = key.getPublicExponent(); } JCERSAPublicKey( SubjectPublicKeyInfo info) { try
* Test for <code>getPublicExponent()</code> method<br> * Assertion: returns public exponent */ public final void testGetPublicExponent() { RSAPublicKeySpec rpks = new RSAPublicKeySpec(BigInteger.valueOf(3L), BigInteger.valueOf(1234567890L)); assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getPublicExponent())); } }
* Test for <code>getPublicExponent()</code> method<br> * Assertion: returns public exponent */ public final void testGetPublicExponent() { RSAPublicKeySpec rpks = new RSAPublicKeySpec(BigInteger.valueOf(3L), BigInteger.valueOf(1234567890L)); assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getPublicExponent())); } }