Standard library / crypto/ed25519

crypto/ed25519.Sign()

Signs raw message bytes using ordinary Ed25519; wrong private key length panics. Do not prehash unless using the explicit prehash variant. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Sign(privateKey PrivateKey, message []byte) []byte

Parameters & Attributes

NameTypeDescription
privateKeyPrivateKeyPrivate signing key; keep secret.
message[]byteMessage bytes or prehash as specified.

Return Value

[]byte

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)  s := ed25519.Sign(k, []byte("Go"))  fmt.Println(ed25519.Verify(pub, []byte("Go"), 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