golang:MD5的几种实现方式
package main
import (
"crypto"
"crypto/md5"
"fmt"
"io"
)
func main() {
{
h := crypto.MD5.New()
io.WriteString(h, "test1280")
fmt.Printf("%x\n", h.Sum(nil))
}
{
h := md5.New()
io.WriteString(h, "test1280")
fmt.Printf("%x\n", h.Sum(nil))
}
{
data := []byte("test1280")
fmt.Printf("%x\n", md5.Sum(data))
}
}
运行:
C:\Users\test1280\Desktop\test1280>go run main.go
6c139d7d77158948d0d390a78a166516
6c139d7d77158948d0d390a78a166516
6c139d7d77158948d0d390a78a166516
参考:https://golang.org/pkg/crypto/md5/