From a4aebc01b818227ec2386878e02005d771da57c8 Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Wed, 17 Jul 2019 14:58:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emd5=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/md5/md5.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 util/md5/md5.go diff --git a/util/md5/md5.go b/util/md5/md5.go new file mode 100644 index 0000000..d0cbe6d --- /dev/null +++ b/util/md5/md5.go @@ -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 +}