I'm creating an API that will use public/private key pairs to authenticate users.
I've been working with both the .NET RSACryptoServiceProvider and the BouncyCastle library to create these pairs.
It works, but the output is far from user friendly. These keys contain all kinds of symbols like +-/=.
I've used several API services that generate public/private keys and these keys are always very neat, with only numbers and letters.
So how can I create more user friendly/reader friendly key pairs? This is the BouncyCastle code I'm using at the moment:
var r = new RsaKeyPairGenerator();
r.Init(new KeyGenerationParameters(new SecureRandom(), keySizeInBits));
var keys = r.GenerateKeyPair();
AsymmetricCipherKeyPair pair = GenerateKeys(64);
PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(pair.Private);
byte[] serializedPrivateBytes = privateKeyInfo.ToAsn1Object().GetDerEncoded();
txtPrivateKey.Text = Convert.ToBase64String(serializedPrivateBytes);
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pair.Public);
byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();
txtPublicKey.Text = Convert.ToBase64String(serializedPublicBytes);
And this is an example output:
MCAwDQYJKoZIhvcN+A+Q+EB/BQADDwAwD/+AIFAMpTPYUCAwEAAQ==
Edit: I've added an image to illustrate. This is from a cryptocoin exchange.
(Obviously these keys are no longer valid).
To use the API you have to encrypt data with your public and private key and send it along using POST.
I've seen many APIs being protected like this, and they all use similar, 'pretty', public/private keys.