md5.go 267 B

12345678910111213141516171819
  1. package common
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "io"
  6. )
  7. func MD5(src string) string {
  8. h := md5.New()
  9. io.WriteString(h, src)
  10. return fmt.Sprintf("%x", h.Sum(nil))
  11. }
  12. func MD5ByLength16(src string) string {
  13. res := MD5(src)
  14. res = res[8:]
  15. res = res[:16]
  16. return res
  17. }