Ragunath

Hi,

I want to sign some data with the private key ( I had the Digital Certificate with the public key alone, but I know the private key, hence I can supply as a string) and decrpt back with the public key from the certificate.

I try to do with .pfx file and the x509certicate2 + RSACryptoServiceProvider class. But I was not able to decrpt back with the public key once if it was sign with the private key from the certificate.

With Thanks,

Ragunath



Re: .NET Base Class Library Using Digital Signature - Signing with Private Key

Feng Chen - MSFT

Hi asowles,

I¡¯m not sure about what exactly do you mean by ¡°I was not able to decrpt back with the public key once if it was sign with the private key from the certificate.¡±, could you please clarify Have you come across any error or exception

Thanks!






Re: .NET Base Class Library Using Digital Signature - Signing with Private Key

Derek Smyth

Hi,

You maybe encrypting the data instead of signing it. RSACryptoProvider is for encrypting data using public/private keys and isn't used to create digital signatures.

Yeah please give some more information.






Re: .NET Base Class Library Using Digital Signature - Signing with Private Key

Ragunath

Hi,

Thanks for your response.

I had two issues.

a. I have a certificate of type .cer where the private key is not present. But I need to sign a hash with the private key and will pass the digital certificate where others can obtain the publlic key. (I know the password / Private key value)

Now I need the methods to do inorder to create the RSACryptoServiceProvider object and sign the hash with the private key related to the certificate.

b. I had a .pfx certificate, where the private key pair is present along with public key. Now I want to sign a data like some string "Hai". I did it with the SignData() present in the RSACryptoServiceProvider. But when I decrypt it with the public key which I obtain from the same certificate, I was not able to decrypt. It throws error, Bad Data.

I need your assistance for doing this.

With Thanks,

Ragunath





Re: .NET Base Class Library Using Digital Signature - Signing with Private Key

Derek Smyth

Hi,

Thats interesting I did not know that RSA could be used to sign data so thanks for that.

Just a quick suggestion do you use the RSACryptoServiceProvider.VerifyData() method to verify the signature

Like this to create (with keys already loaded into RSA)...

byte[] Signature = RSAalg.SignData(OriginalData, new SHA1CryptoServiceProvider());

and then like this to verify (with keys already loaded into RSA)...

RSAalg.VerifyData(OriginalData, new SHA1CryptoServiceProvider(), Signature);