Bouncy Castle, RSA : transforming keys into a String format
- by Rami W.
Hi, iam using RSA(Bouncy Castle API) in my c# porject. Igenerated the keypair with this method
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;
now i want to save them in 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
PrivateKeyInfo k = PrivateKeyInfoFactory.CreatePrivateKeyInfo(private_key);
byte[] serializedKey = k.ToAsn1Object().GetDerEncoded();
Is it the right way ? if yes, what should i do after this ? just convert them from byte[] to String ? thx for any help.