1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00

包装签名函数

This commit is contained in:
2022-06-23 15:46:16 +08:00
parent dce7e8cb9f
commit 79a5d3c935
2 changed files with 16 additions and 0 deletions

View File

@ -12,9 +12,12 @@ import (
"strings"
"github.com/charlienet/go-mixed/bytesconv"
"github.com/charlienet/go-mixed/crypto"
"github.com/tjfoc/gmsm/sm3"
)
var _ crypto.Signer = &hashComparer{}
type HMacFunc func(key, msg []byte) bytesconv.BytesResult
var hmacFuncs = map[string]HMacFunc{
@ -44,6 +47,11 @@ func New(fname string, key []byte) (*hashComparer, error) {
}, nil
}
func (c *hashComparer) Sign(msg []byte) ([]byte, error) {
ret := c.hashFunc(c.key, msg)
return ret.Bytes(), nil
}
func (c *hashComparer) Verify(msg, target []byte) bool {
ret := c.hashFunc(c.key, msg)