go标准库的学习-crypto/md5

时间:2023-03-09 09:15:29
go标准库的学习-crypto/md5

参考:https://studygolang.com/pkgdoc

导入方式:

import "crypto/md5"

md5包实现了MD5哈希算法,参见RFC 1321

Constants

const BlockSize = 

MD5字节块大小。

const Size = 

MD5校验和字节数。

func Sum

func Sum(data []byte) [Size]byte

返回数据data的MD5校验和。

举例:

package main

import (
"fmt"
"crypto/md5"
) func main() {
data := []byte("The fog is getting thicker!And Leon's getting laaarger!")
fmt.Printf("%x\n", md5.Sum(data)) //e2c569be17396eca2a2e3c11578123ed
}

func New

func New() hash.Hash

返回一个新的使用MD5校验的hash.Hash接口。

可见go标准库的学习-hash

举例:

package main

import (
"fmt"
"crypto/md5"
"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\n", h.Sum(nil)) //e2c569be17396eca2a2e3c11578123ed
}