Working with SHA-256

In order to sign and validate an SHA-256 signature, please ensure:
1. If you use .NET 4.5

Add a reference to the System.Deployment assembly.
Add the following code segment to your application’s bootstrap:
C#:

using System.Security.Cryptography;
using System.Deployment.Internal.CodeSigning;
...
protected void Application_Start(object sender, EventArgs e)
{
	Enable SHA-256 XML signature support.
	CryptoConfig.AddAlgorithm(
		 typeof(RSAPKCS1SHA256SignatureDescription),
		 "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
};

2. If you use .NET 3.5 and 4.0

Make sure the following exists in your machine.config file for corresponding .NET Framework (both 32 and 64 bits)

<mscorlib>
<cryptographySettings>
<cryptoNameMapping>
<cryptoClasses>
<cryptoClass RSASHA256SignatureDescription=”Security.Cryptography.RSAPKCS1SHA256SignatureDescription, Security.Cryptography, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
</cryptoClasses>
<nameEntry name=”http://www.w3.org/2001/04/xmldsig-more#rsa-sha256” />
</cryptoNameMapping>
</cryptographySettings>
</mscorlib>

Download the security extension library at: http://clrsecurity.codeplex.com/
Add reference to the newly downloaded assembly

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>