md5.go 421 B

12345678910111213141516171819202122232425
  1. package tools
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "fmt"
  6. "io"
  7. "strings"
  8. )
  9. // Aes加密
  10. func MD5(sourceValue string) string {
  11. w := md5.New()
  12. io.WriteString(w, sourceValue)
  13. newMD5 := fmt.Sprintf("%x", w.Sum(nil))
  14. return strings.ToLower(newMD5)
  15. }
  16. //返回一个32位md5加密后的字符串
  17. func GetMD5Encode(data string) string {
  18. h := md5.New()
  19. h.Write([]byte(data))
  20. return hex.EncodeToString(h.Sum(nil))
  21. }