Generating the SHA hash of a string using golang

后端 未结 8 1678
清酒与你
清酒与你 2020-12-23 16:29

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

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 16:55

    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

提交回复
热议问题