2023-05-17 13:57:50 +08:00
|
|
|
package mycrypto
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|