mycommon/hash.go

28 lines
430 B
Go
Raw Permalink Normal View History

2024-06-20 11:00:14 +08:00
package mycommon
2023-05-17 13:57:50 +08:00
import (
"crypto/md5"
"crypto/sha1"
2023-05-17 14:02:34 +08:00
"crypto/sha256"
2023-05-17 13:57:50 +08:00
"encoding/hex"
)
func Md5(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func Sha1(str string) string {
h := sha1.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
2023-05-17 14:02:34 +08:00
func Sha256(str string) string {
h := sha256.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}