0

Possible Duplicate:
How can I sign a file using RSA and SHA256 with .NET?

I am trying to sign a PDF document with a x509certificate, which has signature algorithm sha256. I have written the following code for this.

RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
rsaCSP.FromXmlString(cert.PrivateKey.ToXmlString(true));
signature = rsaCSP.SignData(dataToBeSigned, CryptoConfig.MapNameToOID("SHA256"));

which yields into an exception saying "Key not valid for specified state"

Then I have made an edit like the following:

RSACryptoServiceProvider rsaCSP = (RSACryptoServiceProvider)cert.PrivateKey;
signature = rsaCSP.SignData(dataToBeSigned, CryptoConfig.MapNameToOID("SHA256"));

This yields into an exception saying "Invalid algorithm specified"

I have no clue for the errors, can anyone help me to get out from this deadlock please ?

4

0 回答 0