title: Bouncy Castle, RSA: transforming keys into a String format
body: <p>I'm using RSA (Bouncy Castle API) in my C# project. I generated the keypair with this method:</p>
  
  <pre><code>RsaKeyPairGenerator r = new RsaKeyPairGenerator();
  r.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
  AsymmetricCipherKeyPair keys = r.GenerateKeyPair();
  
  AsymmetricKeyParameter private_key = keys.Private;
  AsymmetricKeyParameter public_key = keys.Public;
  </code></pre>
  
  <p>Now I want to save them in a txt file but the problem is that I can't convert them to a string format. I read in another post that keys must be serialized using:</p>
  
  <pre><code>PrivateKeyInfo k = PrivateKeyInfoFactory.CreatePrivateKeyInfo(private_key);
  byte[] serializedKey = k.ToAsn1Object().GetDerEncoded();
  </code></pre>
  
  <p>Is it the right way? If yes, what should I do after this? Just convert them from byte[] to String?</p>