参考:https://studygolang.com/pkgdochtml
导入方式:golang
import "crypto/sha1"
sha1包实现了SHA1哈希算法,参见RFC 3174。算法
const BlockSize = 64
SHA1的块大小。post
const Size = 20
SHA1校验和的字节数。学习
func Sum(data []byte) [Size]byte
返回数据data的SHA1校验和。ui
举例:spa
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() hash.Hash
返回一个新的使用SHA1校验的hash.Hash接口。code
可见go标准库的学习-hashhtm
举例:blog
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 }