Standard library / crypto/ecdh
crypto/ecdh.PublicKey.Equal()
Compares public key encodings on matching curves; equivalent encodings can differ. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (k *PublicKey) Equal(x crypto.PublicKey) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | crypto.PublicKey | Other key to compare. |
Return Value
bool
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)) fmt.Println(k.PublicKey().Equal(k.PublicKey()))}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) }}