Standard library / crypto/ecdsa
crypto/ecdsa.PublicKey.ECDH()
Converts a valid supported NIST public point to ECDH format. Unsupported or invalid points return errors. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (k *PublicKey) ECDH() (*ecdh.PublicKey, error)Return Value
(*ecdh.PublicKey, error)
Result as described above; check any returned error before use.
Working Example
Example Snippetgo
package main
import ( "crypto/ecdh" "crypto/ecdsa" "crypto/elliptic" "crypto/rand" "fmt")
func main() { k := must(ecdsa.GenerateKey(elliptic.P256(), rand.Reader)) x := must(k.PublicKey.ECDH()) fmt.Println(x.Curve() == ecdh.P256())}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) }}