加密
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
750 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /*
  2. * For crypter md5
  3. */
  4. package crypter
  5. import (
  6. "crypto/md5"
  7. "encoding/hex"
  8. "strings"
  9. )
  10. //密码加密
  11. func Md5Password(password string, rand ...string) string {
  12. if len(rand) > 0 {
  13. password += rand[0]
  14. }
  15. h := md5.New()
  16. h.Write([]byte(password)) // 需要加密的字符串
  17. cipher2Str := h.Sum(nil)
  18. sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
  19. return sMd5
  20. }
  21. //密码加密
  22. func Md5Str(str ...string) string {
  23. var build strings.Builder
  24. if len(str) > 0 {
  25. for _, v := range str {
  26. build.WriteString(v)
  27. }
  28. } else {
  29. return ""
  30. }
  31. h := md5.New()
  32. h.Write([]byte(build.String())) // 需要加密的字符串
  33. cipher2Str := h.Sum(nil)
  34. sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
  35. return sMd5
  36. }