🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# package sha1 `import "crypto/sha1"` sha1包实现了SHA1哈希算法,参见[RFC 3174](http://tools.ietf.org/html/rfc3174)。 ## Index * [Constants](#pkg-constants) * [func Sum(data []byte) [Size]byte](#Sum) * [func New() hash.Hash](#New) ### Examples * [New](#example-New) * [Sum](#example-Sum) ## Constants ``` const BlockSize = 64 ``` SHA1的块大小。 ``` const Size = 20 ``` SHA1校验和的字节数。 ## func [Sum](https://github.com/golang/go/blob/master/src/crypto/sha1/sha1.go#L125 "View Source") ``` func Sum(data []byte) [Size]byte ``` 返回数据data的SHA1校验和。 Example ``` data := []byte("This page intentionally left blank.") fmt.Printf("% x", sha1.Sum(data)) ``` Output: ``` af 06 49 23 bb f2 30 15 96 aa c4 c2 73 ba 32 17 8e bc 4a 96 ``` ## func [New](https://github.com/golang/go/blob/master/src/crypto/sha1/sha1.go#L51 "View Source") ``` func New() hash.Hash ``` 返回一个新的使用SHA1校验的hash.Hash接口。 Example ``` h := sha1.New() io.WriteString(h, "His money is twice tainted:") io.WriteString(h, " '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 ```