Standard library / crypto/ed25519
crypto/ed25519.GenerateKey()
Generates public and private keys with secure randomness. A nil source uses crypto/rand.Reader. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| rand | io.Reader | Cryptographically secure random source; see description for exceptions. |
Return Value
(PublicKey, PrivateKey, 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) fmt.Println(len(pub) == 32 && len(k) == 64)}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) }}