Search code examples
c#vb.netbouncycastle

BouncyCastle, how long should it take to generate a RSA keypair?


I'm using Bouncy Castle (c#/vb.net version) and generating a 4096-byte RSA Keypair to use in my certificate with this routine:

Public Shared Function GenerateRSAKeypair(keylength As Integer) As AsymmetricCipherKeyPair
    Dim r As New RsaKeyPairGenerator()
    r.Init(New KeyGenerationParameters(New SecureRandom(), keylength))
    Dim keys As AsymmetricCipherKeyPair = r.GenerateKeyPair()
    Return keys
End Function

The procedure works ok, however it takes a very long time, up to one minute (I'm on a 2.4ghz pentium DualCore).

Since I don't have much experience (almost none really) with RSA and all these things, I just wanted to ask if it's normal that it takes so long to generate the key, or if I'm doing something wrong.

Thanks in advance!


Solution

  • After reading some theory about RSA, I can confirm there's nothing wrong with the code, it simply takes that long to generate such a big key.