An important question: why base64 ?
If this is for your own application, you can save the private key as an XML string (much simpler :-).
string xml = x509Certificate2.PrivateKey.ToXmlString (true);
If you want base64 (again for your application), you can export the key (RSAParameters), then concat each byte[] and turn the combined output into a base64 string.
But if you want to interact with other applications that require a base64 private key, you need to know the format (inside the base64 string). For example. in many cases, PEM private keys are encoded (this is base64 with a special header / footer, see example for X509Certificate ).
If this is what you are looking for, you need to first encode the private key in the PKCS # 8 structure, then rotate to base64 and add a header / footer. You can find useful code to do this inside Mono.Security.dll (license code MIT.X11 from the Mono project).
poupou
source share