Standard library / crypto/ecdh

crypto/ecdh.PrivateKey.Bytes()

Returns a copy of secret key encoding; protect like original key. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (k *PrivateKey) Bytes() []byte

Return Value

[]byte

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

Working Example

Example Snippetgo
package main
import (  "crypto/ecdh"  "crypto/rand"  "fmt")
func main() {  k := must(ecdh.X25519().GenerateKey(rand.Reader))  v := must(ecdh.X25519().NewPrivateKey(k.Bytes()))  fmt.Println(v.Equal(k))}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