golang 的 rabbitmq 消费项目
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.

md5.go 793 B

2 years ago
1 year ago
2 years ago
1 year ago
1234567891011121314151617181920212223242526272829303132333435
  1. package utils
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "fmt"
  6. "io"
  7. "strings"
  8. )
  9. func Md5(str string) string {
  10. h := md5.New()
  11. h.Write([]byte(str))
  12. return hex.EncodeToString(h.Sum(nil))
  13. }
  14. /*
  15. MD5ToUpper32 将字符串,转为32位md5加密,返回大写字母
  16. */
  17. func MD5ToUpper32(str string) string {
  18. w := md5.New()
  19. io.WriteString(w, str) //将str写入到w中
  20. md5Str := fmt.Sprintf("%x", w.Sum(nil)) //w.Sum(nil)将w的hash转成[]byte格式
  21. return strings.ToUpper(md5Str)
  22. }
  23. /*
  24. MD5ToLower32 将字符串,转为32位md5加密,返回小写字母
  25. */
  26. func MD5ToLower32(str string) string {
  27. w := md5.New()
  28. io.WriteString(w, str) //将str写入到w中
  29. md5Str := fmt.Sprintf("%x", w.Sum(nil)) //w.Sum(nil)将w的hash转成[]byte格式
  30. return md5Str
  31. }