Standard library / crypto

crypto.Signer

Interface for private signing keys. Public returns the corresponding public key; Sign uses scheme-specific options and possibly randomness. For plain Ed25519 pass the original message with Hash(0), not a digest. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
type Signer interface {  Public() PublicKey
  Sign(rand io.Reader, digest []byte, opts SignerOpts) (signature []byte, err error)}

Working Example

Example Snippetgo
package main
import (  "crypto"  "crypto/ed25519"  "crypto/rand"  "fmt")
func main() {  pub, priv, e := ed25519.GenerateKey(rand.Reader)  if e != nil {    panic(e)  }  var s crypto.Signer = priv  msg := []byte("demo")  sig, e := s.Sign(rand.Reader, msg, crypto.Hash(0))  if e != nil {    panic(e)  }  fmt.Println(ed25519.Verify(pub, msg, sig), s.Public().(ed25519.PublicKey).Equal(pub))}
Go Reference