This commit is contained in:
lzf
2024-06-20 11:00:14 +08:00
parent 2b7c5848fe
commit a5fe1f32db
2 changed files with 14 additions and 5 deletions

27
hash.go Normal file
View File

@@ -0,0 +1,27 @@
package mycommon
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"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))
}
func Sha256(str string) string {
h := sha256.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}