Here is the symptom:
1. You are using RSACryptoServiceProvider for computing SHA-2 signatures.
2. Doing this you get unhandled exceptions of type "System.ArgumentException" in mscorlib.dll saying "Value was invalid".
3. A typical call that failed was:byte[] signature = rsa.SignData(data, new SHA256CryptoServiceProvider());
4. The SHA1CryptoServiceProvider did not reproduce the exception.
5. Additionally you have FIPS policy enabled.
The environment might be Windows Vista and above with .Net Framework version 3.5 or above. The code snippet that reproduces this issue is:
namespace SignData
{
class Program
{
static void Main(string[] args)
{
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 }; using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
SHA256CryptoServiceProvider ha = new SHA256CryptoServiceProvider();
byte[] signature = rsa.SignData(data, ha); if (rsa.VerifyData(data, new SHA256CryptoServiceProvider(), signature))
{
Console.WriteLine("RSA-SHA256 signature verified");
}
else
{
Console.WriteLine("RSA-SHA256 signature failed to verify");
}
}
}
}
}This code is directly referenced from the blog http://blogs.msdn.com/shawnfa/archive/2008/08/25/using-rsacryptoserviceprovider-for-rsa-sha256-signatures.aspx and my intension is to show the exception. Read more: LogIn SDK - Windows SDK team blog
1. You are using RSACryptoServiceProvider for computing SHA-2 signatures.
2. Doing this you get unhandled exceptions of type "System.ArgumentException" in mscorlib.dll saying "Value was invalid".
3. A typical call that failed was:byte[] signature = rsa.SignData(data, new SHA256CryptoServiceProvider());
4. The SHA1CryptoServiceProvider did not reproduce the exception.
5. Additionally you have FIPS policy enabled.
The environment might be Windows Vista and above with .Net Framework version 3.5 or above. The code snippet that reproduces this issue is:
namespace SignData
{
class Program
{
static void Main(string[] args)
{
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 }; using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
SHA256CryptoServiceProvider ha = new SHA256CryptoServiceProvider();
byte[] signature = rsa.SignData(data, ha); if (rsa.VerifyData(data, new SHA256CryptoServiceProvider(), signature))
{
Console.WriteLine("RSA-SHA256 signature verified");
}
else
{
Console.WriteLine("RSA-SHA256 signature failed to verify");
}
}
}
}
}This code is directly referenced from the blog http://blogs.msdn.com/shawnfa/archive/2008/08/25/using-rsacryptoserviceprovider-for-rsa-sha256-signatures.aspx and my intension is to show the exception. Read more: LogIn SDK - Windows SDK team blog
2 comments:
I almost never drop remarks, but i did some searching and wound up here
"Getting a "System.ArgumentException: Value was
invalid" when trying to sign data using SHA256CryptoServiceProvider".
And I do have a few questions for you if it's allright. Could it be just me or does it look like a few of the comments come across like they are left by brain dead visitors? :-P And, if you are posting on additional places, I would like to keep up with anything fresh you have to post. Could you make a list of the complete urls of your public sites like your twitter feed, Facebook page or linkedin profile?
Feel free to visit my page http://loveacougarforwildlife.com/
Excellent blog here! Also your site loads up fast!
What web host are you using? Can I get your affiliate link to your
host? I wish my site loaded up as fast as yours
lol
Money from home
Post a Comment