title: Encrypting a private key with BouncyCastle
body: <p>I'm using the .NET version of BouncyCastle, and I have to save a private RSA key to file, obviously encrypted with a password for security reasons.</p>
  
  <p>What I'm trying right now is this:</p>
  
  <pre><code>Dim rand As New SecureRandom
      Dim arr As Byte() = New Byte(7) {}
      rand.NextBytes(arr)
  
      Dim privateKeyInfo As EncryptedPrivateKeyInfo = EncryptedPrivateKeyInfoFactory.CreateEncryptedPrivateKeyInfo(
  "PBEwithHmacSHA-256",
   Repository.Password.ToCharArray,
   arr,
   1,
   data.BouncyCastlePrivateKey
  )
  </code></pre>
  
  <p>But BouncyCastle is thwrowing a NullReferenceException on the last instruction. Since the method is totally undocumented >:( I wonder if any of you know how to use it correctly...</p>
  
  <p>(none of my parameters are NULL by the way, already checked that)</p>