Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateNonce() (string, error)
- func GetCertificateSerialNumber(certificate x509.Certificate) string
- func HMacEx(h func() hash.Hash, key []byte, bs []byte) string
- func HMacMD5(key []byte, bs []byte) string
- func HMacSHA1(key []byte, bs []byte) string
- func HMacSHA256(key []byte, bs []byte) string
- func IsCertificateExpired(certificate x509.Certificate, now time.Time) bool
- func IsCertificateValid(certificate x509.Certificate, now time.Time) bool
- func LoadCertificate(certificateStr string) (certificate *x509.Certificate, err error)
- func LoadCertificateWithPath(path string) (certificate *x509.Certificate, err error)
- func LoadPrivateKey(privateKeyStr string) (privateKey *rsa.PrivateKey, err error)
- func LoadPrivateKeyWithPath(path string) (privateKey *rsa.PrivateKey, err error)
- func LoadPublicKey(publicKeyStr string) (publicKey *rsa.PublicKey, err error)
- func LoadPublicKeyWithPath(path string) (publicKey *rsa.PublicKey, err error)
- type DefaultEncoder
- type Encoder
- type Hash
- type HashMethod
- type Method
- type Option
- type RSAMethod
- type SignOption
- type SignOptions
- type Signer
Constants ¶
View Source
const ( // NonceSymbols 随机字符串可用字符集 NonceSymbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // NonceLength 随机字符串的长度 NonceLength = 32 )
Variables ¶
View Source
var ErrVerification = errors.New("verification error")
View Source
var MD5 _MD5
View Source
var SHA1 _SHA1
View Source
var SHA256 _SHA256
View Source
var SHA512 _SHA512
Functions ¶
func GenerateNonce ¶
GenerateNonce 生成一个长度为 NonceLength 的随机字符串(只包含大小写字母与数字)
func GetCertificateSerialNumber ¶
func GetCertificateSerialNumber(certificate x509.Certificate) string
GetCertificateSerialNumber 从证书中获取证书序列号
func HMacSHA256 ¶
func IsCertificateExpired ¶
func IsCertificateExpired(certificate x509.Certificate, now time.Time) bool
IsCertificateExpired 判定证书在特定时间是否过期
func IsCertificateValid ¶
func IsCertificateValid(certificate x509.Certificate, now time.Time) bool
IsCertificateValid 判定证书在特定时间是否有效
func LoadCertificate ¶
func LoadCertificate(certificateStr string) (certificate *x509.Certificate, err error)
LoadCertificate 通过证书的文本内容加载证书
func LoadCertificateWithPath ¶
func LoadCertificateWithPath(path string) (certificate *x509.Certificate, err error)
LoadCertificateWithPath 通过证书的文件路径加载证书
func LoadPrivateKey ¶
func LoadPrivateKey(privateKeyStr string) (privateKey *rsa.PrivateKey, err error)
LoadPrivateKey 通过私钥的文本内容加载私钥 通用模式,优先按照 pkcs1 处理。
func LoadPrivateKeyWithPath ¶
func LoadPrivateKeyWithPath(path string) (privateKey *rsa.PrivateKey, err error)
LoadPrivateKeyWithPath 通过私钥的文件路径内容加载私钥
func LoadPublicKey ¶
LoadPublicKey 通过公钥的文本内容加载公钥
Types ¶
type DefaultEncoder ¶
type DefaultEncoder struct { }
func (*DefaultEncoder) EncodeBytes ¶
func (encoder *DefaultEncoder) EncodeBytes(buffer *bytes.Buffer, data []byte, opts *SignOptions) ([]byte, error)
func (*DefaultEncoder) EncodeValues ¶
func (encoder *DefaultEncoder) EncodeValues(buffer *bytes.Buffer, values url.Values, opts *SignOptions) ([]byte, error)
EncodeValues 1、将参数名及其对应的值进行升序排序 2、将排序后的参数名及参数名使用等号进行连接,例如:a=10 3、将组合之后的参数使用&号进行连接,例如:a=10&b=20&c=30&c=31
type HashMethod ¶
type HashMethod struct {
// contains filtered or unexported fields
}
func NewHashMethod ¶
func NewHashMethod(h crypto.Hash) *HashMethod
type RSAMethod ¶
type RSAMethod struct {
// contains filtered or unexported fields
}
func NewRSAMethod ¶
type SignOption ¶
type SignOption func(opt *SignOptions)
func WithIgnore ¶
func WithIgnore(keys ...string) SignOption
func WithPrefix ¶
func WithPrefix(s string) SignOption
func WithSuffix ¶
func WithSuffix(s string) SignOption
type SignOptions ¶
type Signer ¶
type Signer interface { SignValues(ctx context.Context, values url.Values, opts ...SignOption) ([]byte, error) SignBytes(ctx context.Context, data []byte, opts ...SignOption) ([]byte, error) VerifyValues(ctx context.Context, values url.Values, signature []byte, opts ...SignOption) error VerifyBytes(ctx context.Context, data []byte, signature []byte, opts ...SignOption) error }
Click to show internal directories.
Click to hide internal directories.