Digital Signature

dhanasekar

New member
Joined
Oct 27, 2005
Messages
2
Programming Experience
1-3
Hi,
I have problem while matching digital signature.
I need to create a digital signature for a message.
The message digest is generated using SHA-1 algorithm.
Then it is encrypted with private key (using RSA ECB and PKCS#1 v1.5 padding) and converted to printable Hex.

I am getting "Key not valid for use in specified state" error while encrypt. (Bolded line).

I got the certificate from one CA (EMX Co).
Is there any solution for this.

The code is as follows:

Imports System.Security
Imports System.Security.Cryptography
Imports Microsoft.Web.Services.Security
Imports Microsoft.Web.Services.Security.X509

Dim cert As X509Certificate = GetCertificate() 'Certificate from my certificate store.

'Receiver's Public Key
Dim receiver_public As RSAParameters = cert.Key.ExportParameters(False)
'Sender's Private key
'********************
Dim senders_private As RSAParameters = cert.Key.ExportParameters(True)
Dim rsaCSP AsNew System.Security.Cryptography.RSACryptoServiceProvider
rsaCSP.ImportParameters(receiver_public)
'Asymmetric encryption with receivers's public key
Dim clearText() AsByte = System.Text.Encoding.BigEndianUnicode.GetBytes(Message)
Dim digest() AsByte = rsaCSP.Encrypt(clearText, False)
'Sign the cipher with own private key
rsaCSP = New System.Security.Cryptography.RSACryptoServiceProvider
rsaCSP.ImportParameters(senders_private)
Dim signature() AsByte = rsaCSP.SignHash(digest, CryptoConfig.MapNameToOID("SHA1"))

'Convert to printable Hex
Dim b AsByte
Dim hexString AsString
ForEach b In signature
hexString +=
String.Format("{0:X2}", b)
Next

Return hexString.ToLower



Thanks
Dhanasekar.
 
Back
Top