新增md5工具库

This commit is contained in:
boyce
2019-07-17 14:58:02 +08:00
parent 4271a4fd78
commit a4aebc01b8

28
util/md5/md5.go Normal file
View File

@@ -0,0 +1,28 @@
package md5
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
)
func Md5V(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func Md5V2(str string) string {
data := []byte(str)
has := md5.Sum(data)
md5str := fmt.Sprintf("%x", has)
return md5str
}
func Md5V3(str string) string {
w := md5.New()
io.WriteString(w, str)
md5str := fmt.Sprintf("%x", w.Sum(nil))
return md5str
}