|
|
@ -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 |
|
|
|
} |