utils

package
v0.2.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 80

Documentation

Index

Constants

View Source
const (
	// NonceSymbols 随机字符串可用字符集
	NonceSymbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	// NonceLength 随机字符串的长度
	NonceLength = 32
)

Variables

This section is empty.

Functions

func DecryptAES256GCM added in v0.2.0

func DecryptAES256GCM(aesKey, associatedData, nonce, ciphertext string) (plaintext string, err error)

DecryptAES256GCM 使用 AEAD_AES_256_GCM 算法进行解密

你可以使用此算法完成微信支付平台证书和回调报文解密,详见: https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/zheng-shu-he-hui-tiao-bao-wen-jie-mi

func DecryptOAEP

func DecryptOAEP(ciphertext string, privateKey *rsa.PrivateKey) (message string, err error)

DecryptOAEP 使用私钥进行解密

func DecryptPKCS1v15 added in v0.2.13

func DecryptPKCS1v15(ciphertext string, privateKey *rsa.PrivateKey) (message string, err error)

DecryptPKCS1v15 使用私钥对PKCS1 padding方式加密的字符串进行解密

func EncryptOAEPWithCertificate

func EncryptOAEPWithCertificate(message string, certificate *x509.Certificate) (ciphertext string, err error)

EncryptOAEPWithCertificate 先解析出证书中的公钥,然后使用 OAEP padding方式公钥进行加密

func EncryptOAEPWithPublicKey

func EncryptOAEPWithPublicKey(message string, publicKey *rsa.PublicKey) (ciphertext string, err error)

EncryptOAEPWithPublicKey 使用 OAEP padding方式用公钥进行加密

func EncryptPKCS1v15WithCertificate added in v0.2.13

func EncryptPKCS1v15WithCertificate(message string, certificate *x509.Certificate) (ciphertext string, err error)

EncryptPKCS1v15WithCertificate 先解析出证书中的公钥,然后使用PKCS1 padding方式用公钥进行加密

func EncryptPKCS1v15WithPublicKey added in v0.2.13

func EncryptPKCS1v15WithPublicKey(message string, publicKey *rsa.PublicKey) (ciphertext string, err error)

EncryptPKCS1v15WithPublicKey 使用PKCS1 padding方式用公钥进行加密

func GenerateNonce added in v0.2.1

func GenerateNonce() (string, error)

GenerateNonce 生成一个长度为 NonceLength 的随机字符串(只包含大小写字母与数字)

func GetCertificateSerialNumber added in v0.2.0

func GetCertificateSerialNumber(certificate x509.Certificate) string

GetCertificateSerialNumber 从证书中获取证书序列号

func IsCertExpired deprecated added in v0.2.0

func IsCertExpired(certificate x509.Certificate, now time.Time) bool

IsCertExpired 判定证书在特定时间是否过期

Deprecated: 请使用 IsCertificateExpired

func IsCertValid deprecated added in v0.2.0

func IsCertValid(certificate x509.Certificate, now time.Time) bool

IsCertValid 判定证书在特定时间是否有效

Deprecated: 请使用 IsCertificateValid

func IsCertificateExpired added in v0.2.12

func IsCertificateExpired(certificate x509.Certificate, now time.Time) bool

IsCertificateExpired 判定证书在特定时间是否过期

func IsCertificateValid added in v0.2.12

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 通过私钥的文本内容加载私钥

func LoadPrivateKeyWithPath

func LoadPrivateKeyWithPath(path string) (privateKey *rsa.PrivateKey, err error)

LoadPrivateKeyWithPath 通过私钥的文件路径内容加载私钥

func LoadPublicKey

func LoadPublicKey(publicKeyStr string) (publicKey *rsa.PublicKey, err error)

LoadPublicKey 通过公钥的文本内容加载公钥

func LoadPublicKeyWithPath

func LoadPublicKeyWithPath(path string) (publicKey *rsa.PublicKey, err error)

LoadPublicKeyWithPath 通过公钥的文件路径加载公钥

func SignSHA256WithRSA added in v0.2.0

func SignSHA256WithRSA(source string, privateKey *rsa.PrivateKey) (signature string, err error)

SignSHA256WithRSA 通过私钥对字符串以 SHA256WithRSA 算法生成签名信息

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL