1// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build gccgo_examples
6
7package ecdsa_test
8
9import (
10	"crypto/ecdsa"
11	"crypto/elliptic"
12	"crypto/rand"
13	"crypto/sha256"
14	"fmt"
15)
16
17func Example() {
18	privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
19	if err != nil {
20		panic(err)
21	}
22
23	msg := "hello, world"
24	hash := sha256.Sum256([]byte(msg))
25
26	sig, err := ecdsa.SignASN1(rand.Reader, privateKey, hash[:])
27	if err != nil {
28		panic(err)
29	}
30	fmt.Printf("signature: %x\n", sig)
31
32	valid := ecdsa.VerifyASN1(&privateKey.PublicKey, hash[:], sig)
33	fmt.Println("signature verified:", valid)
34}
35