Standard library / crypto/ecdh
crypto/ecdh.PublicKey
Opaque peer public share. Parse with the matching curve; authenticating the peer requires a protocol beyond ECDH. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type PublicKey struct {}Working Example
Example Snippetgo
package main
import ( "crypto/ecdh" "crypto/rand" "fmt")
func main() { k := must(ecdh.X25519().GenerateKey(rand.Reader)) var p *ecdh.PublicKey = k.PublicKey() fmt.Println(p.Curve() == ecdh.X25519())}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) }}