T
Tamas Nyari
Hello,
We have a small digital signing toolkit, that uses a smart card provider to
sign hashed data. We used System.Security.Cryptography namesapce in .NET 1.1.
Here is the code part that makes the signing function.
string defKey = "<the name of key container>"; //You should change for
yours.
string clearText = "This will be signed.";
clearText = richTextBox1.Text;
System.IO.MemoryStream strm = new System.IO.MemoryStream();
byte[] byteArr = System.Text.UTF8Encoding.UTF8.GetBytes(clearText);
strm.Write(byteArr, 0, byteArr.Length);
strm.Position = 0;
string hashAlg = "SHA1";
string hashOID = CryptoConfig.MapNameToOID(hashAlg);
SHA1 sh1 = SHA1Managed.Create();
byte[] hash = sh1.ComputeHash(strm);
CspParameters cspParam = new CspParameters();
cspParam.ProviderType = 1; // PROV_RSA_FULL
cspParam.ProviderName = "Axalto Cryptographic Service Provider";
cspParam.KeyContainerName = defKey;//"Cyberflex Access 64K (v2c)";
cspParam.KeyNumber = 2;
RSACryptoServiceProvider rsaCSP = new
RSACryptoServiceProvider(cspParam);
byte[] signed = rsaCSP.SignHash(hash, hashOID);
string signedText = System.Text.UTF8Encoding.UTF8.GetString(signed);
rsaCSP.Clear(); //CSP felszabadÃtás
This is works for us in .NET 1.1, but when we try it in .NET 2.0, we get the
following error at SignHash function:
-2146893812 (8009000C) Hash not valid for use in specified state.
OS: MS Windows XP professional with SP build 2600
I.e 6.0.2900.2180
Ms Enchanced Cryptographic Provider : rsaenh.dll
version 5.1.2600.2161
Axalto : xltCsp.dll
version: 5.01.0011.0
What could be the problem? What is the difference between .NET 1.1 and 2.0?
Thanks:
Tamas
We have a small digital signing toolkit, that uses a smart card provider to
sign hashed data. We used System.Security.Cryptography namesapce in .NET 1.1.
Here is the code part that makes the signing function.
string defKey = "<the name of key container>"; //You should change for
yours.
string clearText = "This will be signed.";
clearText = richTextBox1.Text;
System.IO.MemoryStream strm = new System.IO.MemoryStream();
byte[] byteArr = System.Text.UTF8Encoding.UTF8.GetBytes(clearText);
strm.Write(byteArr, 0, byteArr.Length);
strm.Position = 0;
string hashAlg = "SHA1";
string hashOID = CryptoConfig.MapNameToOID(hashAlg);
SHA1 sh1 = SHA1Managed.Create();
byte[] hash = sh1.ComputeHash(strm);
CspParameters cspParam = new CspParameters();
cspParam.ProviderType = 1; // PROV_RSA_FULL
cspParam.ProviderName = "Axalto Cryptographic Service Provider";
cspParam.KeyContainerName = defKey;//"Cyberflex Access 64K (v2c)";
cspParam.KeyNumber = 2;
RSACryptoServiceProvider rsaCSP = new
RSACryptoServiceProvider(cspParam);
byte[] signed = rsaCSP.SignHash(hash, hashOID);
string signedText = System.Text.UTF8Encoding.UTF8.GetString(signed);
rsaCSP.Clear(); //CSP felszabadÃtás
This is works for us in .NET 1.1, but when we try it in .NET 2.0, we get the
following error at SignHash function:
-2146893812 (8009000C) Hash not valid for use in specified state.
OS: MS Windows XP professional with SP build 2600
I.e 6.0.2900.2180
Ms Enchanced Cryptographic Provider : rsaenh.dll
version 5.1.2600.2161
Axalto : xltCsp.dll
version: 5.01.0011.0
What could be the problem? What is the difference between .NET 1.1 and 2.0?
Thanks:
Tamas