Standard library / crypto/ecdsa

crypto/ecdsa.Verify()

Checks the supplied digest and two signature integers against a public key. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool

Parameters & Attributes

NameTypeDescription
pub*PublicKeyPublic key used for the operation.
hash[]byteHash algorithm, hash instance or digest as specified by the signature and description.
r*big.IntFirst ECDSA signature integer.
s*big.IntSecond ECDSA signature integer.

Return Value

bool

Result as described above; check any returned error before use.

Working Example

Example Snippetgo
package main
import (  "crypto/ecdsa"  "crypto/elliptic"  "crypto/rand"  "crypto/sha256"  "fmt")
func main() {  k := must(ecdsa.GenerateKey(elliptic.P256(), rand.Reader))  h := sha256.Sum256([]byte("Go"))  r, s, err := ecdsa.Sign(rand.Reader, k, h[:])  check(err)  fmt.Println(ecdsa.Verify(&k.PublicKey, h[:], r, s))}func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference