Documentation ¶
Index ¶
- func AESDecryptCBC(key, iv, data []byte) ([]byte, error)
- func AESDecryptECB(key, data []byte) ([]byte, error)
- func AESDecryptGCM(key, nonce []byte, data, aad []byte, opt *GCMOption) ([]byte, error)
- func DESDecryptECB(key, data []byte) ([]byte, error)
- func DESEncryptECB(key, data []byte) ([]byte, error)
- func LoadCertFromPfxFile(filename, password string) (tls.Certificate, error)
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- type CipherText
- type GCMOption
- type PrivateKey
- func (pk *PrivateKey) Decrypt(data []byte) ([]byte, error)
- func (pk *PrivateKey) DecryptOAEP(hash crypto.Hash, data []byte) ([]byte, error)
- func (pk *PrivateKey) Sign(hash crypto.Hash, data []byte) ([]byte, error)
- func (pk *PrivateKey) SignPSS(hash crypto.Hash, data []byte, opts *rsa.PSSOptions) ([]byte, error)
- type PublicKey
- func NewPublicKeyFromDerBlock(pemBlock []byte) (*PublicKey, error)
- func NewPublicKeyFromDerFile(pemFile string) (*PublicKey, error)
- func NewPublicKeyFromPemBlock(padding RSAPadding, pemBlock []byte) (*PublicKey, error)
- func NewPublicKeyFromPemFile(padding RSAPadding, pemFile string) (*PublicKey, error)
- func (pk *PublicKey) Encrypt(data []byte) ([]byte, error)
- func (pk *PublicKey) EncryptOAEP(hash crypto.Hash, data []byte) ([]byte, error)
- func (pk *PublicKey) Verify(hash crypto.Hash, data, signature []byte) error
- func (pk *PublicKey) VerifyPSS(hash crypto.Hash, data, signature []byte, opts *rsa.PSSOptions) error
- type RSAPadding
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESDecryptCBC ¶
AESDecryptCBC AES-CBC 解密(pkcs#7)
func AESDecryptECB ¶
AESDecryptECB AES-ECB 解密(pkcs#7)
func AESDecryptGCM ¶
AESDecryptGCM AES-GCM 解密 (默认:NonceSize = 12 & TagSize = 16)
func LoadCertFromPfxFile ¶
func LoadCertFromPfxFile(filename, password string) (tls.Certificate, error)
LoadCertFromPfxFile 通过pfx(p12)证书文件生成TLS证书 注意:证书需采用「TripleDES-SHA1」加密方式
func NewECBDecrypter ¶
NewECBDecrypter 生成ECB解密器
Types ¶
type CipherText ¶
type CipherText struct {
// contains filtered or unexported fields
}
CipherText 加密文本
func AESEncryptCBC ¶
func AESEncryptCBC(key, iv, data []byte, paddingSize ...uint8) (*CipherText, error)
AESEncryptCBC AES-CBC 加密(pkcs#7, 默认填充BlockSize)
func AESEncryptECB ¶
func AESEncryptECB(key, data []byte, paddingSize ...uint8) (*CipherText, error)
AESEncryptECB AES-ECB 加密(pkcs#7, 默认填充BlockSize)
func AESEncryptGCM ¶
func AESEncryptGCM(key, nonce, data, aad []byte, opt *GCMOption) (*CipherText, error)
AESEncryptGCM AES-GCM 加密 (默认:NonceSize = 12 & TagSize = 16)
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey RSA私钥
func NewPrivateKeyFromPemBlock ¶
func NewPrivateKeyFromPemBlock(padding RSAPadding, pemBlock []byte) (*PrivateKey, error)
NewPrivateKeyFromPemBlock 通过PEM字节生成RSA私钥
func NewPrivateKeyFromPemFile ¶
func NewPrivateKeyFromPemFile(padding RSAPadding, pemFile string) (*PrivateKey, error)
NewPrivateKeyFromPemFile 通过PEM文件生成RSA私钥
func NewPrivateKeyFromPfxFile ¶
func NewPrivateKeyFromPfxFile(pfxFile, password string) (*PrivateKey, error)
NewPrivateKeyFromPfxFile 通过pfx(p12)证书生成RSA私钥 注意:证书需采用「TripleDES-SHA1」加密方式
func (*PrivateKey) Decrypt ¶
func (pk *PrivateKey) Decrypt(data []byte) ([]byte, error)
Decrypt RSA私钥 PKCS#1 v1.5 解密
func (*PrivateKey) DecryptOAEP ¶
DecryptOAEP RSA私钥 PKCS#1 OAEP 解密
func (*PrivateKey) SignPSS ¶
func (pk *PrivateKey) SignPSS(hash crypto.Hash, data []byte, opts *rsa.PSSOptions) ([]byte, error)
SignPSS RSA私钥签名(PSS填充)
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey RSA公钥
func NewPublicKeyFromDerBlock ¶
NewPublicKeyFromDerBlock 通过DER字节生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem
func NewPublicKeyFromDerFile ¶
NewPublicKeyFromDerFile 通过DER证书生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem
func NewPublicKeyFromPemBlock ¶
func NewPublicKeyFromPemBlock(padding RSAPadding, pemBlock []byte) (*PublicKey, error)
NewPublicKeyFromPemBlock 通过PEM字节生成RSA公钥
func NewPublicKeyFromPemFile ¶
func NewPublicKeyFromPemFile(padding RSAPadding, pemFile string) (*PublicKey, error)
NewPublicKeyFromPemFile 通过PEM文件生成RSA公钥
func (*PublicKey) EncryptOAEP ¶
EncryptOAEP RSA公钥 PKCS#1 OAEP 加密
type RSAPadding ¶
type RSAPadding int
RSAPadding RSA PEM 填充模式
const ( RSA_PKCS1 RSAPadding = 1 // PKCS#1 (格式:`RSA PRIVATE KEY` & `RSA PUBLIC KEY`) RSA_PKCS8 RSAPadding = 8 // PKCS#8 (格式:`PRIVATE KEY` & `PUBLIC KEY`) )