包含Go API项目的所有源代码、配置文件、Docker配置、文档和前端资源 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
35 lines
591 B
Go
35 lines
591 B
Go
package common
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/sha1"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
)
|
|
|
|
func Sha256Raw(data []byte) []byte {
|
|
h := sha256.New()
|
|
h.Write(data)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func Sha1Raw(data []byte) []byte {
|
|
h := sha1.New()
|
|
h.Write(data)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func Sha1(data []byte) string {
|
|
return hex.EncodeToString(Sha1Raw(data))
|
|
}
|
|
|
|
func HmacSha256Raw(message, key []byte) []byte {
|
|
h := hmac.New(sha256.New, key)
|
|
h.Write(message)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func HmacSha256(message, key string) string {
|
|
return hex.EncodeToString(HmacSha256Raw([]byte(message), []byte(key)))
|
|
}
|