Golang crypto/dsa.Verify() function example

package crypto/dsa

Verify function verifies the signature using the given public key input against the hash and r,s integers. It reports whether the signature is valid.

Golang crypto/dsa.Verify() function usage example

 var pubkey dsa.PublicKey
 pubkey = privatekey.PublicKey

 ...

 var h hash.Hash
 h = md5.New()
 r := big.NewInt(0)
 s := big.NewInt(0)

 io.WriteString(h, "This is the message to be signed and verified!")
 signhash := h.Sum(nil)

 r, s, err := dsa.Sign(rand.Reader, privatekey, signhash)
 if err != nil {
 fmt.Println(err)
 }

 // Verify
 verifystatus := dsa.Verify(&pubkey, signhash, r, s)
 fmt.Println(verifystatus) // should be true

See How to use DSA functions tutorial for more details

Reference :

http://golang.org/pkg/crypto/dsa/#Verify

Advertisement