package main
import (
"crypto/md5"
"fmt"
"io"
)
func main() {
str := "123456"
fmt.Print(Md5one(str))
fmt.Print("------------")
fmt.Print(Md5two(str))
}
func Md5one(str string) (md5str string) {
data := []byte(str)
has := md5.Sum(data)
md5str = fmt.Sprintf("%x", has)
return
}
func Md5two(str string) (md5str string) {
h := md5.New()
io.WriteString(h, str)
md5str = fmt.Sprintf("%x", h.Sum(nil))
return
}
有疑问加站长微信联系(非本文作者)