Search in sources :

Example 51 with RSAPrivateCrtKeySpec

use of java.security.spec.RSAPrivateCrtKeySpec in project tink by google.

the class SelfKeyTestValidatorsTest method createRsaKey.

private final void createRsaKey(int bitLength) throws Exception {
    String[] keyInfo = getRsaKeyInfo(bitLength);
    KeyFactory kf = EngineFactory.KEY_FACTORY.getInstance("RSA");
    publicRsaKey = (RSAPublicKey) kf.generatePublic(new RSAPublicKeySpec(new BigInteger(keyInfo[0].substring(keyInfo[0].length() - (bitLength / 4)), 16), BigInteger.valueOf(65537)));
    privateRsaKey = (RSAPrivateCrtKey) kf.generatePrivate(new RSAPrivateCrtKeySpec(new BigInteger(keyInfo[0], 16), BigInteger.valueOf(65537), new BigInteger(keyInfo[1], 16), new BigInteger(keyInfo[2], 16), new BigInteger(keyInfo[3], 16), new BigInteger(keyInfo[4], 16), new BigInteger(keyInfo[5], 16), new BigInteger(keyInfo[6], 16)));
}
Also used : RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec) BigInteger(java.math.BigInteger) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) KeyFactory(java.security.KeyFactory)

Aggregations

RSAPrivateCrtKeySpec (java.security.spec.RSAPrivateCrtKeySpec)51 KeyFactory (java.security.KeyFactory)18 BigInteger (java.math.BigInteger)16 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)12 PrivateKey (java.security.PrivateKey)11 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)10 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)10 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)9 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)8 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)8 PublicKey (java.security.PublicKey)7 KeySpec (java.security.spec.KeySpec)6 IOException (java.io.IOException)5 KeyPair (java.security.KeyPair)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 GeneralSecurityException (java.security.GeneralSecurityException)4 InvalidKeyException (java.security.InvalidKeyException)4 Signature (java.security.Signature)4 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)4 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)4