xcrypto

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecryptCBC

func AESDecryptCBC(key, iv, data []byte) ([]byte, error)

AESDecryptCBC AES-CBC 解密(pkcs#7)

func AESDecryptECB

func AESDecryptECB(key, data []byte) ([]byte, error)

AESDecryptECB AES-ECB 解密(pkcs#7)

func AESDecryptGCM

func AESDecryptGCM(key, nonce []byte, data, aad []byte, opt *GCMOption) ([]byte, error)

AESDecryptGCM AES-GCM 解密 (默认:NonceSize = 12 & TagSize = 16)

func DESDecryptECB

func DESDecryptECB(key, data []byte) ([]byte, error)

DESDecryptECB DES-ECB 解密

func DESEncryptECB

func DESEncryptECB(key, data []byte) ([]byte, error)

DESEncryptECB DES-ECB 加密

func LoadCertFromPfxFile

func LoadCertFromPfxFile(filename, password string) (tls.Certificate, error)

LoadCertFromPfxFile 通过pfx(p12)证书文件生成TLS证书 注意:证书需采用「TripleDES-SHA1」加密方式

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter 生成ECB解密器

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter 生成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)

func (*CipherText) Bytes

func (ct *CipherText) Bytes() []byte

Bytes 获取加密数据的bytes

func (*CipherText) Data

func (ct *CipherText) Data() []byte

Data 获取GCM加密数据的真实数据

func (*CipherText) String

func (ct *CipherText) String() string

Bytes 返回加密数据base64字符串

func (*CipherText) Tag

func (ct *CipherText) Tag() []byte

Tag 获取GCM加密数据的tag

type GCMOption

type GCMOption struct {
	TagSize   int
	NonceSize int
}

GCMOption AES-GCM 加密选项(二选一),指定 TagSize[12, 16] 和 NonceSize(0, ~)

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

func (pk *PrivateKey) DecryptOAEP(hash crypto.Hash, data []byte) ([]byte, error)

DecryptOAEP RSA私钥 PKCS#1 OAEP 解密

func (*PrivateKey) Sign

func (pk *PrivateKey) Sign(hash crypto.Hash, data []byte) ([]byte, error)

Sign RSA私钥签名

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

func NewPublicKeyFromDerBlock(pemBlock []byte) (*PublicKey, error)

NewPublicKeyFromDerBlock 通过DER字节生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem

func NewPublicKeyFromDerFile

func NewPublicKeyFromDerFile(pemFile string) (*PublicKey, error)

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) Encrypt

func (pk *PublicKey) Encrypt(data []byte) ([]byte, error)

Encrypt RSA公钥 PKCS#1 v1.5 加密

func (*PublicKey) EncryptOAEP

func (pk *PublicKey) EncryptOAEP(hash crypto.Hash, data []byte) ([]byte, error)

EncryptOAEP RSA公钥 PKCS#1 OAEP 加密

func (*PublicKey) Verify

func (pk *PublicKey) Verify(hash crypto.Hash, data, signature []byte) error

Verify RSA公钥验签

func (*PublicKey) VerifyPSS

func (pk *PublicKey) VerifyPSS(hash crypto.Hash, data, signature []byte, opts *rsa.PSSOptions) error

VerifyPSS RSA公钥验签(PSS填充)

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`)
)

Jump to

Keyboard shortcuts

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