?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
import "crypto/md5"
概述
索引
示例
md5 包實現(xiàn)了 RFC 1321 中定義的 MD5 哈希算法。
MD5 是加密破解的,不應(yīng)用于安全應(yīng)用程序。
Constants
func New() hash.Hash
func Sum(data []byte) [Size]byte
New New (File) Sum
md5.go md5block.go md5block_decl.go
以字節(jié)為單位的MD5塊大小。
const BlockSize = 64
MD5 校驗和的大?。ㄒ宰止?jié)為單位)。
const Size = 16
func New() hash.Hash
New 返回一個新的散列.Hash 計算 MD5 校驗和。
package mainimport ("crypto/md5""fmt""io")func main() { h := md5.New() io.WriteString(h, "The fog is getting thicker!") io.WriteString(h, "And Leon's getting laaarger!") fmt.Printf("%x", h.Sum(nil))}
package mainimport ("crypto/md5""fmt""io""log""os")func main() { f, err := os.Open("file.txt")if err != nil { log.Fatal(err)} defer f.Close() h := md5.New()if _, err := io.Copy(h, f); err != nil { log.Fatal(err)} fmt.Printf("%x", h.Sum(nil))}
func Sum(data []byte) [Size]byte
總和返回數(shù)據(jù)的 MD5 校驗和。
package mainimport ("crypto/md5""fmt")func main() { data := []byte("These pretzels are making me thirsty.") fmt.Printf("%x", md5.Sum(data))}