Ver Fonte

新增md5工具

dcsunny há 4 anos atrás
pai
commit
7213dcbe44
1 ficheiros alterados com 19 adições e 0 exclusões
  1. 19 0
      common/md5.go

+ 19 - 0
common/md5.go

@@ -0,0 +1,19 @@
+package common
+
+import (
+	"crypto/md5"
+	"fmt"
+	"io"
+)
+
+func MD5(src string) string {
+	h := md5.New()
+	io.WriteString(h, src)
+	return fmt.Sprintf("%x", h.Sum(nil))
+}
+func MD5ByLength16(src string) string {
+	res := MD5(src)
+	res = res[8:]
+	res = res[:16]
+	return res
+}