plugins/crypto/crypt/Hash.go

31 lines
503 B
Go
Raw Permalink Normal View History

2024-01-25 16:07:48 +08:00
package crypt
import (
2024-06-26 12:17:41 +08:00
"crypto/sha256"
2024-01-25 16:07:48 +08:00
"github.com/ZZMarquis/gm/sm3"
"hash"
)
func (c *CMCrypt) NewHash() hash.Hash {
2024-06-26 12:17:41 +08:00
return sha256.New()
2024-01-25 16:07:48 +08:00
}
func (c *GMCrypt) NewHash() hash.Hash {
return sm3.New()
}
func (c *CMCrypt) Hash(data ...[]byte) []byte {
return makeHash(c.NewHash(), data...)
}
func (c *GMCrypt) Hash(data ...[]byte) []byte {
return makeHash(c.NewHash(), data...)
}
func makeHash(h hash.Hash, data ...[]byte) []byte {
for _, b := range data {
h.Write(b)
}
return h.Sum(nil)
2024-06-26 12:17:41 +08:00
}