Search code examples
c#encryptionrsacryptoserviceprovider

What is the correct way for saving a cryptographic key?


I have:

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

And either one of these:

byte[] Csp = rsa.ExportCspBlob(true);
RSAParameters parameters = rsa.ExportParameters(true);

What is the correct way to save them, and what file extension should be used? Note: I'm not referring to how to encrypt them. Just how to store them.


Solution

  • I would just use the RSACryptoServiceProvider.PersistKeyInCsp = true. Make sue that the CspParameters.KeyContainerName contains a unique identifiable name for they key.

    To transfer the public key around, use the export to Xml methods.