123456789101112131415161718192021222324252627282930313233343536 |
- package sha
- import (
- "crypto/hmac"
- "crypto/md5"
- "crypto/sha1"
- "crypto/sha256"
- "fmt"
- "io"
- )
- func ComputeSHA1(data string) string {
- t := sha1.New()
- _, _ = io.WriteString(t, data)
- return fmt.Sprintf("%x", t.Sum(nil))
- }
- func ComputeMD5(data string) string {
- t := md5.New()
- _, _ = io.WriteString(t, data)
- return fmt.Sprintf("%x", t.Sum(nil))
- }
- func ComputeHmacSha256(message string, secret string) string {
- key := []byte(secret)
- h := hmac.New(sha256.New, key)
- h.Write([]byte(message))
- return fmt.Sprintf("%x", h.Sum(nil))
- }
- func ComputeSha256(message string) []byte {
- p := []byte(message)
- h := sha256.New()
- h.Write(p)
- return h.Sum(nil)
- }
|