Standard library / crypto/ecdsa
crypto/ecdsa.VerifyASN1()
Checks an ASN.1 DER signature. Invalid or malformed signatures return false. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func VerifyASN1(pub *PublicKey, hash, sig []byte) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| pub | *PublicKey | Public key used for the operation. |
| hash | []byte | Hash algorithm, hash instance or digest as specified by the signature and description. |
| sig | []byte | Signature bytes to verify. |
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")) s := must(ecdsa.SignASN1(rand.Reader, k, h[:])) fmt.Println(ecdsa.VerifyASN1(&k.PublicKey, h[:], 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) }}