1 Star 0 Fork 0

monobytes/gcore

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
signer_options.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
null 提交于 2025-01-22 18:29 +08:00 . first commit
package rsa
import (
"gitee.com/monobytes/gcore/getc"
"gitee.com/monobytes/gcore/gwrap/hash"
"strings"
)
const (
defaultSignerHashKey = "etc.crypto.rsa.signer.hash"
defaultSignerPaddingKey = "etc.crypto.rsa.signer.padding"
defaultSignerPublicKeyKey = "etc.crypto.rsa.signer.publicKey"
defaultSignerPrivateKeyKey = "etc.crypto.rsa.signer.privateKey"
)
type SignerOption func(o *signerOptions)
type signerOptions struct {
// hash算法。支持sha1、sha224、sha256、sha384、sha512
// 默认为sha256
hash hash.Hash
// 填充规则。支持PKCS和PSS
// 默认为PSS
padding SignPadding
// 公钥。可设置文件路径或公钥串
publicKey string
// 私钥。可设置文件路径或私钥串
privateKey string
}
func defaultSignerOptions() *signerOptions {
return &signerOptions{
hash: hash.Hash(strings.ToLower(getc.Get(defaultSignerHashKey).String())),
padding: SignPadding(strings.ToUpper(getc.Get(defaultSignerPaddingKey).String())),
publicKey: getc.Get(defaultSignerPublicKeyKey).String(),
privateKey: getc.Get(defaultSignerPrivateKeyKey).String(),
}
}
// WithSignerHash 设置加密hash算法
func WithSignerHash(hash hash.Hash) SignerOption {
return func(o *signerOptions) { o.hash = hash }
}
// WithSignerPadding 设置加密填充规则
func WithSignerPadding(padding SignPadding) SignerOption {
return func(o *signerOptions) { o.padding = padding }
}
// WithSignerPublicKey 设置验签公钥
func WithSignerPublicKey(publicKey string) SignerOption {
return func(o *signerOptions) { o.publicKey = publicKey }
}
// WithSignerPrivateKey 设置解密私钥
func WithSignerPrivateKey(privateKey string) SignerOption {
return func(o *signerOptions) { o.privateKey = privateKey }
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/monobytes/gcore.git
git@gitee.com:monobytes/gcore.git
monobytes
gcore
gcore
v0.0.11

搜索帮助