From b7c529105e5a8b8d616fb4349289e67e0984c23c Mon Sep 17 00:00:00 2001 From: Coda Hale Date: Tue, 20 Aug 2013 17:46:11 -0700 Subject: [PATCH] Add an example to the readme. --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 2e6ecda..cb3e0ba 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,31 @@ rfc6979 ======= A Go implementation of RFC 6979's deterministic DSA/ECDSA signature scheme. + +``` go +package main + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/sha512" + "fmt" + "github.com/codahale/rfc6979" +) + +func main() { + // Generate a key pair. + // You need a high-quality PRNG for this. + k, _ := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) + + // Hash a message. + alg := sha512.New() + alg.Write([]byte("I am a potato.")) + hash := alg.Sum(nil) + + r, s, _ := rfc6979.SignECDSA(k, hash, sha512.New) + fmt.Printf("Signature: %X%X", r, s) +} + +```