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
}
网友评论