|
@ -6,10 +6,12 @@ package crypter |
|
|
import ( |
|
|
import ( |
|
|
"crypto/md5" |
|
|
"crypto/md5" |
|
|
"encoding/hex" |
|
|
"encoding/hex" |
|
|
|
|
|
"strings" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
//密码加密
|
|
|
//密码加密
|
|
|
func Md5Password(password string, rand ...string) string { |
|
|
func Md5Password(password string, rand ...string) string { |
|
|
|
|
|
|
|
|
if len(rand) > 0 { |
|
|
if len(rand) > 0 { |
|
|
password += rand[0] |
|
|
password += rand[0] |
|
|
} |
|
|
} |
|
@ -20,3 +22,22 @@ func Md5Password(password string, rand ...string) string { |
|
|
sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
|
|
|
sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
|
|
|
return sMd5 |
|
|
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 |
|
|
|
|
|
} |