Search code examples
javarsabouncycastle

How to create a BCRSAPrivateCrtKey object using CRT parameters?


For my CA there is a database running in the background storing RSA keys by their CRT parameters. Now a BCRSAPrivateCrtKey object shall be created by using the stored information in the database.

Hopefully you can help.

So is there any way to create a key object by using:

RSAPrivateCrtKeyParameters param = new RSAPrivateCrtKeyParameters(modulus,
        publicExponent, privateExponent, p, q, dP, dQ, qInv);

Solution

  • RSAPrivateCrtKeySpec prvkeySpec = new RSAPrivateCrtKeySpec(
            modulus, publicExponent, privateExponent, primeP,
            primeQ, primeExponentP, primeExponentQ,
            crtCoefficient);
    Security.addProvider(new org.bouncycastle.jce
            .provider.BouncyCastleProvider());
    KeyFactory kfact = KeyFactory.getInstance("RSA", "BC");
    BCRSAPrivateCrtKey prk = (BCRSAPrivateCrtKey) kfact
           .generatePrivate(prvkeySpec);