How do I ensure that RSACryptoServiceProvider always creates a new key pair?

316 Views Asked by At

This answer nicely explains how to create a new public/private key pair in .NET:

public static void AssignNewKey(){
    RSA rsa = new RSACryptoServiceProvider(2048); // Generate a new 2048 bit RSA key

    string publicPrivateKeyXML = rsa.ToXmlString(true);
    string publicOnlyKeyXML = rsa.ToXmlString(false);
    // do stuff with keys...
}

However, the "Remarks" section in the documentation of RSACryptoServiceProvider(Int32) says (emphasis mine):

Remarks

If no default key is found, a new key is created. [...]

What is this "default key" and how can I make sure that the RSACryptoServiceProvider constructor does not return that "default key" but a new key?

0

There are 0 best solutions below