title: Bouncy Castle RSA keypair generation using Lightweight API
body: <p>Surprisingly enough there's very little information on the Web about using Bouncy Castle's lightweight API. After looking around for a while I was able to put together a basic example:</p>
  
  <pre><code>RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
  generator.init(new RSAKeyGenerationParameters
      (
          new BigInteger("10001", 16),//publicExponent
          SecureRandom.getInstance("SHA1PRNG"),//prng
          1024,//strength
          80//certainty
      ));
  
  AsymmetricCipherKeyPair keyPair = generator.generateKeyPair();
  </code></pre>
  
  <p>I have a basic understanding of RSA and the math that happens behind the scenes, so I understand what <code>publicExponent</code> and <code>strength</code> are. I presume <code>publicExponent</code> refers to a coprime of <code>phi(pq)</code> and from what I gather it can be small (like 3) as long as appropriate padding is used. However, I have no idea what <code>certainty</code> refers to (some place mentioned that it might refer to a percentage but I want to be sure). The use of <code>SecureRandom</code> is self-explanatory. The <a href="http://www.bouncycastle.org/docs/docs1.6/index.html" rel="noreferrer">documentation of RSAKeyGenerationParameters</a> is completely worthless (no surprise there). My only guess is that it has something to do with the accuracy of the generated keys, but again I want to be sure. So my question is what are appropriate values for <code>certainty</code> and <code>publicExponent</code>?</p>
  
  <p>P.S.
  Please don't reply with "it depends on the context - how secure you want the information to be". It's pretty safe to assume highest degree of security (i.e. 4096-bit RSA key or greater) unless otherwise specified... I would also appreciate links to sources that give good example of the use of Bouncy Castle's Lightweight API (I'm not at all interested in the JCA implementation or any examples pertaining to it).</p>