參考: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 }