title: Creating RSA public/private key pair with Bouncy Castle or .Net RSACryptoServiceProvider
body: <p>So I've messed around a bit with .Net's RSACryptoServiceProvider and Bouncy Castle to be able to create RSA key pairs and later on X509 certificates.</p>
  
  <p>I'm just curious if anyone knows if there's any difference between these two codeblocks, which I think does the same thing, but the pure Bouncy Castle version takes much longer to finish.</p>
  
  <p>.Net with Bouncy Castle:</p>
  
  <pre><code>private const int RsaKeySize = 4096;
  public static AsymmetricCipherKeyPair GetKeyPairWithDotNet()
  {
     using (RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(RsaKeySize))
     {
        RSAParameters rsaKeyInfo = rsaProvider.ExportParameters(true);
        return DotNetUtilities.GetRsaKeyPair(rsaKeyInfo);
     }
  }
  </code></pre>
  
  <p>Pure Bouncy Castle:</p>
  
  <pre><code>private const int RsaKeySize = 4096;
  public static AsymmetricCipherKeyPair GetKeyPair()
  {
     CryptoApiRandomGenerator randomGenerator = new CryptoApiRandomGenerator();
     SecureRandom secureRandom = new SecureRandom(randomGenerator);
     var keyGenerationParameters = new KeyGenerationParameters(secureRandom, RsaKeySize);
  
     var keyPairGenerator = new RsaKeyPairGenerator();
     keyPairGenerator.Init(keyGenerationParameters);
     return keyPairGenerator.GenerateKeyPair();
  }
  </code></pre>