Home All Groups Group Topic Archive Search About

Sign hash with public key

Author
20 Sep 2006 8:19 PM
Daniel Godoy
Hello all !

    I´ve developed a page to do a Asymmetric Cryptography with Digital
Certificate, but something doesn´t work.

    I have a URL like that :
"FIELD1=000000000000001&FIELD2=0000&FIELD3=AAAAA&SIGN=5705236f1f462afe65f6704d24c8e1359fead41e42c460d........"

    When I receive it, I have to get the Digital Signature of all field and
after compare with the SIGN field. But I can´t cryptography the field using
"SIGNHASH", because my Certificate File (CER) haven´t the Private Key, and
the same time, I can´t use the VERIFYHASH, because I don´t know how convert
the SIGN value to a array of bytes.

    The code :
'TextBox1.text = ClearText

'TextBox2.text = SIGN

Dim ClearTextBytes As Byte() = Encoding.UTF8.GetBytes(TextBox1.Text)

Dim AlgHash As HashAlgorithm = HashAlgorithm.Create("SHA1")

Dim hash As Byte() = AlgHash.ComputeHash(ClearTextBytes)

Dim Cert As X509Certificate =
X509Certificate.CreateCertFromFile("C:\CertificateFile.cer")

Dim sign As New RSACryptoServiceProvider

sign.ImportParameters(Cert.PublicKey.ExportParameters(False))

Dim b As Byte

Dim resultHexString As String

MsgBox(sign.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), "????I have
to convert, but I don´t know how ????"))



Thank you !!



Daniel Godoy

Author
21 Sep 2006 8:19 AM
Valery Pryamikov
You can encrypt with public key and decrypt with private.
You can sign with private key and verify with public.

Tha'ts one of the reasons it was called ASYMMETRIC cryptography.

-Valery.
http://www.harper.no/valery

Daniel Godoy wrote:
Show quoteHide quote
> Hello all !
>
>     I´ve developed a page to do a Asymmetric Cryptography with Digital
> Certificate, but something doesn´t work.
>
>     I have a URL like that :
> "FIELD1=000000000000001&FIELD2=0000&FIELD3=AAAAA&SIGN=5705236f1f462afe65f6704d24c8e1359fead41e42c460d........"
>
>     When I receive it, I have to get the Digital Signature of all field and
> after compare with the SIGN field. But I can´t cryptography the field using
> "SIGNHASH", because my Certificate File (CER) haven´t the Private Key, and
> the same time, I can´t use the VERIFYHASH, because I don´t know how convert
> the SIGN value to a array of bytes.
>
>     The code :
> 'TextBox1.text = ClearText
>
> 'TextBox2.text = SIGN
>
> Dim ClearTextBytes As Byte() = Encoding.UTF8.GetBytes(TextBox1.Text)
>
> Dim AlgHash As HashAlgorithm = HashAlgorithm.Create("SHA1")
>
> Dim hash As Byte() = AlgHash.ComputeHash(ClearTextBytes)
>
> Dim Cert As X509Certificate =
> X509Certificate.CreateCertFromFile("C:\CertificateFile.cer")
>
> Dim sign As New RSACryptoServiceProvider
>
> sign.ImportParameters(Cert.PublicKey.ExportParameters(False))
>
> Dim b As Byte
>
> Dim resultHexString As String
>
> MsgBox(sign.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), "????I have
> to convert, but I don´t know how ????"))
>
>
>
> Thank you !!
>
>
>
> Daniel Godoy