参考:https://studygolang.com/pkgdoc
导入方式:
import "crypto/sha1"
sha1包实现了SHA1哈希算法,参见RFC 3174。
Constants
const BlockSize =
SHA1的块大小。
const Size =
SHA1校验和的字节数。
func Sum
func Sum(data []byte) [Size]byte
返回数据data的SHA1校验和。
举例:
package main import (
"fmt"
"crypto/sha1"
) func main() {
data := []byte("His money is twice tainted: 'taint yours and 'taint mine.")
fmt.Printf("%x\n", sha1.Sum(data)) //597f6a540010f94c15d71806a99a2c8710e747bd
}
func New
func New() hash.Hash
返回一个新的使用SHA1校验的hash.Hash接口。
举例:
package main import (
"fmt"
"crypto/sha1"
"io"
) func main() {
h := sha1.New()
io.WriteString(h, "His money is twice tainted:")
io.WriteString(h, " 'taint yours and 'taint mine.")
fmt.Printf("%x\n", h.Sum(nil)) //597f6a540010f94c15d71806a99a2c8710e747bd
}