github.com/tickstep/library-go@v0.1.1/crypto/hmac.go (about) 1 package crypto 2 3 import ( 4 "crypto/hmac" 5 "crypto/md5" 6 "crypto/sha1" 7 "crypto/sha256" 8 "crypto/sha512" 9 ) 10 11 // HmacSHA1 HMAC-SHA-1签名认证 12 func HmacSHA1(key, origData []byte) (sum []byte) { 13 mac := hmac.New(sha1.New, key) 14 mac.Write(origData) 15 return mac.Sum(nil) 16 } 17 18 // HmacSHA256 HMAC-SHA-256签名认证 19 func HmacSHA256(key, origData []byte) (sum []byte) { 20 mac := hmac.New(sha256.New, key) 21 mac.Write(origData) 22 return mac.Sum(nil) 23 } 24 25 // HmacSHA512 HMAC-SHA-512签名认证 26 func HmacSHA512(key, origData []byte) (sum []byte) { 27 mac := hmac.New(sha512.New, key) 28 mac.Write(origData) 29 return mac.Sum(nil) 30 } 31 32 // HmacMD5 HMAC-SHA512-签名认证 33 func HmacMD5(key, origData []byte) (sum []byte) { 34 mac := hmac.New(md5.New, key) 35 mac.Write(origData) 36 return mac.Sum(nil) 37 }