Using RSACryptoServiceProvider on Azure website results in file not found error

I am moving an existing (and working) ASP.NET website to an Azure website. One of the bits of functionality on the site is XML document signing. Key code:

// retrieve a key from the key safe - this will create it if it does not exist yet
System.Security.Cryptography.CspParameters csp = new CspParameters();
csp.KeyContainerName = "MyKeyName";
System.Security.Cryptography.RSACryptoServiceProvider key = new RSACryptoServiceProvider(csp);

      

The last line throws a CryptographicException with the message "The system cannot find the file specified."

I am not adding a key or container to Azure - I understand that the ServiceProvider will create it. I looked through this article but didn't get any clues.

Clearly I have missed something fundamental.

+3


source to share


1 answer


Thanks Simon - this pointed me in the right direction.

It turns out that you need to specify that the key should be created in the machine store. Code that worked:



System.Security.Cryptography.CspParameters csp = new CspParameters();
csp.KeyContainerName = "MyKeyName";
csp.Flags = CspProviderFlags.UseMachineKeyStore;

      

Notice the addition of a line indicating "UseMachineKeyStore"

+6


source







All Articles