BouncyCastle Crypto - RSA Key pair generation

kenneth.leekenneth.lee USMember ✭✭✭

Hi Everyone,

I'm kind of new to crypto and I would like some clarification if what I'm doing is correct.

First I need to generate a RSA public and private key pair on PCL and decided to with BouncyCastle.
I need to do this with OAEP padding, 4098 bit strength and 95537 as its public exponent.

Without much documentation on BouncyCastle C# API I wrote ...

    public static AsymmetricCipherKeyPair CreateRSAKey()
    {
        RsaKeyPairGenerator g = new RsaKeyPairGenerator();
        g.Init(new KeyGenerationParameters(new SecureRandom(), 4096));
        return g.GenerateKeyPair();
    }

Just wondering if the RsaKeyPairGenerator defaults to OAEP padding and 65537 public exponent cause im lost as to where i parse or init these values on to the Generator.

Answers

  • kenneth.leekenneth.lee USMember ✭✭✭

    After more googling my function now looks like this.

        public static AsymmetricCipherKeyPair CreateRSAKey()
        {
            RsaKeyPairGenerator g = new RsaKeyPairGenerator();
            Org.BouncyCastle.Math.BigInteger publicExponent = new Org.BouncyCastle.Math.BigInteger(65537);
            var param = new RsaKeyGenerationParameters(publicExponent, SecureRandom.GetInstance(), 4096, 5);
            g.Init(param);
            return g.GenerateKeyPair();
        }
    

    And it seems that the OAEP Padding goes after im generated the RSA Keys

Sign In or Register to comment.