代码拉取完成,页面将自动刷新
package dongle
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"hash"
"gitee.com/golang-module/dongle/md2"
"github.com/emmansun/gmsm/sm3"
"golang.org/x/crypto/md4"
"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/sha3"
)
// ByHmacMd2 encrypts by hmac with md2.
// 通过 hmac-md2 加密
func (e Encrypter) ByHmacMd2(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(md2.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacMd4 encrypts by hmac with md4.
// 通过 hmac-md4 加密
func (e Encrypter) ByHmacMd4(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(md4.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacMd5 encrypts by hmac with md5.
// 通过 hmac-md5 加密
func (e Encrypter) ByHmacMd5(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(md5.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSha1 encrypts by hmac with sha1.
// 通过 hmac-sha1 加密
func (e Encrypter) ByHmacSha1(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(sha1.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSha3 encrypts by hmac with sha3.
// 通过 hmac-sha3 加密
func (e Encrypter) ByHmacSha3(key interface{}, size int) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
var f func() hash.Hash
switch size {
case 224:
f = sha3.New224
case 256:
f = sha3.New256
case 384:
f = sha3.New384
case 512:
f = sha3.New512
default:
e.Error = invalidHashSizeError()
return e
}
h := hmac.New(f, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSha224 encrypts by hmac with sha224.
// 通过 hmac-sha224 加密
func (e Encrypter) ByHmacSha224(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(sha256.New224, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSha256 encrypts by hmac with sha256.
// 通过 hmac-sha256 加密
func (e Encrypter) ByHmacSha256(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(sha256.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSha384 encrypts by hmac with sha384.
// 通过 hmac-sha384 加密
func (e Encrypter) ByHmacSha384(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(sha512.New384, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSha512 encrypts by hmac with sha512.
// 通过 hmac-sha512 加密
func (e Encrypter) ByHmacSha512(key interface{}, size ...int) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
var f func() hash.Hash
if len(size) == 0 {
size = []int{512}
}
switch size[0] {
case 512:
f = sha512.New
case 224:
f = sha512.New512_224
case 256:
f = sha512.New512_256
default:
e.Error = invalidHashSizeError()
return e
}
h := hmac.New(f, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacRipemd160 encrypts by hmac with ripemd160.
// 通过 hmac-ripemd160 加密
func (e Encrypter) ByHmacRipemd160(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(ripemd160.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
// ByHmacSm3 encrypts by hmac with sm3.
// 通过 hmac-sm3 加密
func (e Encrypter) ByHmacSm3(key interface{}) Encrypter {
if len(e.src) == 0 || e.Error != nil {
return e
}
h := hmac.New(sm3.New, interface2bytes(key))
h.Write(e.src)
e.dst = h.Sum(nil)
return e
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。