md5.go 456 B

123456789101112131415161718192021222324252627
  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. return strings.ToUpper(newMD5)
  16. }
  17. //返回一个32位md5加密后的字符串
  18. func GetMD5Encode(data string) string {
  19. h := md5.New()
  20. h.Write([]byte(data))
  21. return hex.EncodeToString(h.Sum(nil))
  22. }