Browse Source

增加MD5方法

master v0.2.0
guzeng 3 years ago
parent
commit
36a9fbc2e1
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      md5.go

+ 21
- 0
md5.go View File

@ -6,10 +6,12 @@ package crypter
import (
"crypto/md5"
"encoding/hex"
"strings"
)
//密码加密
func Md5Password(password string, rand ...string) string {
if len(rand) > 0 {
password += rand[0]
}
@ -20,3 +22,22 @@ func Md5Password(password string, rand ...string) string {
sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
return sMd5
}
//密码加密
func Md5Str(str ...string) string {
var build strings.Builder
if len(str) > 0 {
for _, v := range rand {
build.WriteString(v)
}
} else {
return ""
}
h := md5.New()
h.Write([]byte(build.String())) // 需要加密的字符串
cipher2Str := h.Sum(nil)
sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
return sMd5
}

Loading…
Cancel
Save