package crypto import ( "crypto/hmac" "crypto/md5" "crypto/sha1" "crypto/sha256" "crypto/sha512" "encoding/hex" ) // Md5Hmac return the hmac hash of string use md5 func (c *Crypto) Md5Hmac(data, key string) string { h := hmac.New(md5.New, []byte(key)) h.Write([]byte(data)) return hex.EncodeToString(h.Sum([]byte(""))) } // Sha1Hmac return the hmac hash of string use sha1 func (c *Crypto) Sha1Hmac(data, key string) string { h := hmac.New(sha1.New, []byte(key)) h.Write([]byte(data)) return hex.EncodeToString(h.Sum([]byte(""))) } // Sha256Hmac return the hmac hash of string use sha256 func (c *Crypto) Sha256Hmac(data, key string) string { h := hmac.New(sha256.New, []byte(key)) h.Write([]byte(data)) return hex.EncodeToString(h.Sum([]byte(""))) } // Sha512Hmac return the hmac hash of string use sha512 func (c *Crypto) Sha512Hmac(data, key string) string { h := hmac.New(sha512.New, []byte(key)) h.Write([]byte(data)) return hex.EncodeToString(h.Sum([]byte(""))) }