1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package hash
- import (
- "crypto/hmac"
- "crypto/md5"
- "crypto/sha1"
- "crypto/sha256"
- "crypto/sha512"
- )
- // HmacMD5 hmac md5 hash
- func HmacMD5(k, bs []byte) (hs []byte, err error) {
- h := hmac.New(md5.New, k)
- _, err = h.Write(bs)
- if err != nil {
- return
- }
- hs = h.Sum(nil)
- return
- }
- // HmacSHA1 hmac sha1 hash
- func HmacSHA1(k, bs []byte) (hs []byte, err error) {
- h := hmac.New(sha1.New, k)
- _, err = h.Write(bs)
- if err != nil {
- return
- }
- hs = h.Sum(nil)
- return
- }
- // HmacSHA256 hmac sha256 hash
- func HmacSHA256(k, bs []byte) (hs []byte, err error) {
- h := hmac.New(sha256.New, k)
- _, err = h.Write(bs)
- if err != nil {
- return
- }
- hs = h.Sum(nil)
- return
- }
- // HmacSHA512 hmac sha256 hash
- func HmacSHA512(k, bs []byte) (hs []byte, err error) {
- h := hmac.New(sha512.New, k)
- _, err = h.Write(bs)
- if err != nil {
- return
- }
- hs = h.Sum(nil)
- return
- }
|