I am moving an existing (and working) ASP.NET web site to Azure web site. One of the bits of functionality on the site is signing an XML document. The code to get the key is:
// 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 is throwing a CryptographicException, with the message "The system cannot find the file specified".
I have not put a key or container into Azure - my understanding is that the ServiceProvider would create one. I have reviewed this article, but did not get any clues.
Clearly I am missing something fundamental.
Thanks Simon - that pointed me in the right direction.
Turns out you need to specify that the key be created in a machine store. Code that worked is:
System.Security.Cryptography.CspParameters csp = new CspParameters();
csp.KeyContainerName = "MyKeyName";
csp.Flags = CspProviderFlags.UseMachineKeyStore;
Note the addition of the line specifying "UseMachineKeyStore"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With