import ( "crypto/elliptic" "crypto/rand" "math/big" ) func main() { curve := elliptic.P256() privateKey, _ := ecdsa.GenerateKey(curve, rand.Reader) publicKey := &privateKey.PublicKey x := publicKey.X.Bytes() y := publicKey.Y.Bytes() fmt.Printf("Private key: %x\n", privateKey.D) fmt.Printf("Public key: %x%x\n", x, y) }
import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" "crypto/sha256" "math/big" ) func main() { curve := elliptic.P256() privateKey, _ := ecdsa.GenerateKey(curve, rand.Reader) message := []byte("Hello World") hash := sha256.Sum256(message) r, s, _ := ecdsa.Sign(rand.Reader, privateKey, hash[:]) publicKey := &privateKey.PublicKey valid := ecdsa.Verify(publicKey, hash[:], r, s) fmt.Printf("Valid signature? %v\n", valid) }In both examples, the package being used is "crypto/elliptic".