Tuesday, November 23, 2010

Make SHA256CryptoServiceProvider work on Windows XP SP3

I was trying to verify an SHA256 signature (don't ask) and so I had to use the class SHA256CryptoServiceProvider. Alas, the constructor promptly threw an exception telling me the class is not supported on my system. I googled it and found this answer: C# - SHA256CryptoServiceProvider and related possible to use on WinXP?. Whereas the link reports this is a bug in .NET 3.5 I am working with version 4.0 and it is still there.

Apparently, the constructor of SHA256CryptoServiceProvider looks for a certain name in the cryptography providers installed on the machine. It looks for "Microsoft Enhanced RSA and AES Cryptographic Provider" and it gets the XP variant "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)". The solution is to export the key, remove "(Prototype)" and install the resulting reg file. Then it works. Here is the file, as it resulted on my computer:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Enhanced RSA and AES Cryptographic Provider]
"Image Path"="rsaenh.dll"


Mansee said...

Excellent !!! Solved my issue.