Can someone show me a working example of how to generate a SHA hash of a string that I have, say myPassword := \"beautiful\"
, using Go 1 ?
The docs pa
The package documentation at http://golang.org/pkg/crypto/sha1/ does have an example that demonstrates this. It's stated as an example of the New function, but it's the only example on the page and it has a link right near the top of the page so it is worth looking at. The complete example is,
Code:
h := sha1.New()
io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
fmt.Printf("% x", h.Sum(nil))
Output:
59 7f 6a 54 00 10 f9 4c 15 d7 18 06 a9 9a 2c 87 10 e7 47 bd
h := sha1.New()
h.Write(content)
sha := h.Sum(nil) // "sha" is uint8 type, encoded in base16
shaStr := hex.EncodeToString(sha) // String representation
fmt.Printf("%x\n", sha)
fmt.Println(shaStr)