2

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!

Master_T
  • 7,232
  • 11
  • 72
  • 144
  • The code looks similar to the key generation seen in http://stackoverflow.com/questions/844997/encrypting-a-bouncycastle-rsa-key-pair-and-storing-in-a-sql2008-database as such I suspect that is as long as it takes. Have you profiled the steps to see where the time is being spent? – Shaun Wilde May 08 '12 at 23:25
  • Yeah, I had taken the code from there :D Guess there's no solution other than waiting... probably I'll invoke the method asynchronously then, else my UI freezes for one minute... Thanks. – Master_T May 09 '12 at 20:42

1 Answers1

1

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.

Master_T
  • 7,232
  • 11
  • 72
  • 144