Source file
src/crypto/md5/example_test.go
1
2
3
4
5 package md5_test
6
7 import (
8 "crypto/md5"
9 "fmt"
10 "io"
11 "log"
12 "os"
13 )
14
15 func 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
21 }
22
23 func ExampleSum() {
24 data := []byte("These pretzels are making me thirsty.")
25 fmt.Printf("%x", md5.Sum(data))
26
27 }
28
29 func 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
View as plain text