1234567891011121314151617181920212223242526272829 |
- package toolkit
- import (
- "crypto/md5"
- "crypto/sha1"
- "crypto/sha256"
- "encoding/hex"
- )
- // SHA2 hash string
- func SHA2(data string) string {
- hash := sha256.New()
- hash.Write([]byte(data))
- return hex.EncodeToString(hash.Sum(nil))
- }
- // MD5 hash string
- func MD5(data string) string {
- hash := md5.New()
- hash.Write([]byte(data))
- return hex.EncodeToString(hash.Sum(nil))
- }
- // SHA1 hash string
- func SHA1(data string) string {
- hash := sha1.New()
- hash.Write([]byte(data))
- return hex.EncodeToString(hash.Sum(nil))
- }
|