password.go 427 B

123456789101112131415161718192021222324
  1. package utils
  2. import (
  3. "crypto/md5"
  4. "crypto/sha256"
  5. "fmt"
  6. "io"
  7. )
  8. func GenSaltPassword(salt, password string) string {
  9. s1 := sha256.New()
  10. s1.Write([]byte(password))
  11. str1 := fmt.Sprintf("%x", s1.Sum(nil))
  12. s2 := sha256.New()
  13. s2.Write([]byte(str1 + salt))
  14. return fmt.Sprintf("%x", s2.Sum(nil))
  15. }
  16. //MD5 md5加密
  17. func MD5(s string) string {
  18. h := md5.New()
  19. io.WriteString(h, s)
  20. return fmt.Sprintf("%x", h.Sum(nil))
  21. }