See Also: CryptoConvert Members
Converting private keys into byte arrays may cause security risks. You should always zeroize buffers with sensitive informations after their use.
C# Example
// create a 1024 bits key pair
RSA rsa = RSA.Create ();
// convert the key pair into a CryptoAPI PRIVATEKEYBLOB
byte[] keypair = CryptoConvert.ToCapiKeyBlob (rsa, true);
// save the key pair to a file
using (FileStream fs = File.OpenWrite ("my.key")) {
fs.Write (keypair, 0, keypair.Length);
}
// zeroize the key pair from memory
Array.Clear (keypair, 0, keypair.Length);
// note: the private key still exists in the RSA instance!