title: How to properly use Bouncy Castle's OAEPEncoding for RSA (Lightweight API)
body: <p>I've been playing around with Bouncy Castle's implementation of RSA (Lightweight API) and got the basics figured out. Looking at their <a href="http://www.bouncycastle.org/specifications.html" rel="noreferrer">spec</a> for JCE provider implementation I noticed that different padding schemes can be used with RSA. From what I understand, by default null padding is used. So I began exploring OAEP padding, particularly <code>OAEPWithSHA512AndMGF1Padding</code>. Searching with Google wasn't very helpful so I began digging through BC's source code and found <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.bouncycastle/bcprov-jdk16/1.44/org/bouncycastle/jce/provider/JCERSACipher.java" rel="noreferrer"><code>org.bouncycastle.jce.provider.JCERSACipher</code></a> class. But looking at <code>initFromSpec</code> quickly gave me a headache... Specifically, I don't understand what the last two parameters that can be passed to the <code>OAEPEncoding</code> constructor are. According to BC's API the <a href="http://www.bouncycastle.org/docs/docs1.6/index.html" rel="noreferrer"><code>OAEPEncoding</code></a> constructor that allows four parameters accepts <code>Digest mgf1Hash</code> and <code>byte[] encodingParams</code> as the last two arguments. This stumped me because I have no idea how to get a hold of an instance of the mask generation algorithm nor do I understand the purpose behind the byte array referred to as <code>encodingParams</code>. What should be the values of <code>arg3</code> and <code>arg4</code> in the code below?</p>
  
  <pre><code>RSABlindedEngine rsa = new RSABlindedEngine();
  SHA512Diges sha512 = new SHA512Digest();
  Digest arg3 = ???;
  byte[] arg4 = ???;
  AsymmetricBlockCipher cipher = new OAEPEncoding(rsa, sha512, arg3, arg4);
  </code></pre>