Cryptography error

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top