Standard library / crypto/ed25519

crypto/ed25519.VerifyWithOptions()

Verifies variant selected by Options: ordinary, context-bound or SHA-512 prehashed Ed25519. Must match signing options; returns error on failure. Wrong public key length panics, so validate length first. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func VerifyWithOptions(publicKey PublicKey, message, sig []byte, opts *Options) error

Parameters & Attributes

NameTypeDescription
publicKeyPublicKeyPublic verification key.
message[]byteMessage bytes or prehash as specified.
sig[]byteSignature bytes to verify.
opts*OptionsAlgorithm-specific options; see description for nil behavior.

Return Value

error

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

Working Example

Example Snippetgo
package main
import (  "crypto/ed25519"  "crypto/rand"  "fmt")
func main() {  pub, k, err := ed25519.GenerateKey(rand.Reader)  check(err)  o := &ed25519.Options{Context: "demo"}  s := must(k.Sign(nil, []byte("Go"), o))  fmt.Println(ed25519.VerifyWithOptions(pub, []byte("Go"), s, o) == nil)}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