Bouncy Castle, RSA : transforming keys into a String format
Posted
by
Rami W.
on Stack Overflow
See other posts from Stack Overflow
or by Rami W.
Published on 2011-02-23T12:01:50Z
Indexed on
2011/02/28
23:25 UTC
Read the original article
Hit count: 332
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.
© Stack Overflow or respective owner