1// Copyright 2013 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 5package md5_test 6 7import ( 8 "crypto/md5" 9 "fmt" 10 "io" 11 "log" 12 "os" 13) 14 15func ExampleNew() { 16 h := md5.New() 17 io.WriteString(h, "The fog is getting thicker!") 18 io.WriteString(h, "And Leon's getting laaarger!") 19 fmt.Printf("%x", h.Sum(nil)) 20 // Output: e2c569be17396eca2a2e3c11578123ed 21} 22 23func ExampleSum() { 24 data := []byte("These pretzels are making me thirsty.") 25 fmt.Printf("%x", md5.Sum(data)) 26 // Output: b0804ec967f48520697662a204f5fe72 27} 28 29func ExampleNew_file() { 30 f, err := os.Open("file.txt") 31 if err != nil { 32 log.Fatal(err) 33 } 34 defer f.Close() 35 36 h := md5.New() 37 if _, err := io.Copy(h, f); err != nil { 38 log.Fatal(err) 39 } 40 41 fmt.Printf("%x", h.Sum(nil)) 42} 43