encrypt

package
v1.0.1042 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AES128CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES128CBC is the 128-bit key AES cipher in CBC mode.

View Source
var AES128CCM = CipherCCM{
	// contains filtered or unexported fields
}

AES128CCM is the 128-bit key AES cipher in CCM mode.

View Source
var AES128CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

AES128CCMb is the 128-bit key AES cipher in CCM mode.

View Source
var AES128CFB = CipherCFB{
	// contains filtered or unexported fields
}

AES128CFB is the 128-bit key AES cipher in CFB mode.

View Source
var AES128ECB = CipherECB{
	// contains filtered or unexported fields
}

AES128ECB is the 128-bit key AES cipher in ECB mode.

View Source
var AES128GCM = CipherGCM{
	// contains filtered or unexported fields
}

AES128GCM is the 128-bit key AES cipher in GCM mode.

View Source
var AES128GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

AES128GCMb is the 128-bit key AES cipher in GCM mode.

View Source
var AES128OFB = CipherOFB{
	// contains filtered or unexported fields
}

AES128OFB is the 128-bit key AES cipher in OFB mode.

View Source
var AES192CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES192CBC is the 192-bit key AES cipher in CBC mode.

View Source
var AES192CCM = CipherCCM{
	// contains filtered or unexported fields
}

AES192CCM is the 192-bit key AES cipher in CCM mode.

View Source
var AES192CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

AES192CCMb is the 192-bit key AES cipher in CCM mode.

View Source
var AES192CFB = CipherCFB{
	// contains filtered or unexported fields
}

AES192CFB is the 192-bit key AES cipher in CFB mode.

View Source
var AES192ECB = CipherECB{
	// contains filtered or unexported fields
}

AES192ECB is the 192-bit key AES cipher in ECB mode.

View Source
var AES192GCM = CipherGCM{
	// contains filtered or unexported fields
}

AES192GCM is the 192-bit key AES cipher in GCM mode.

View Source
var AES192GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

AES192GCMb is the 192-bit key AES cipher in GCM mode.

View Source
var AES192OFB = CipherOFB{
	// contains filtered or unexported fields
}

AES192OFB is the 192-bit key AES cipher in OFB mode.

View Source
var AES256CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES256CBC is the 256-bit key AES cipher in CBC mode.

View Source
var AES256CCM = CipherCCM{
	// contains filtered or unexported fields
}

AES256CCM is the 256-bit key AES cipher in CCM mode.

View Source
var AES256CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

AES256CCMb is the 256-bit key AES cipher in CCM mode.

View Source
var AES256CFB = CipherCFB{
	// contains filtered or unexported fields
}

AES256CFB is the 256-bit key AES cipher in CFB mode.

View Source
var AES256ECB = CipherECB{
	// contains filtered or unexported fields
}

AES256ECB is the 256-bit key AES cipher in ECB mode.

View Source
var AES256GCM = CipherGCM{
	// contains filtered or unexported fields
}

AES256GCM is the 256-bit key AES cipher in GCM mode.

View Source
var AES256GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

AES256GCMb is the 256-bit key AES cipher in GCM mode.

View Source
var AES256OFB = CipherOFB{
	// contains filtered or unexported fields
}

AES256OFB is the 256-bit key AES cipher in OFB mode.

View Source
var DESCBC = CipherCBC{
	// contains filtered or unexported fields
}

DESCBC is the 56-bit key 3DES cipher in CBC mode.

View Source
var DESEDE3CBC = CipherCBC{
	// contains filtered or unexported fields
}

TripleDESCBC is the 168-bit key 3DES cipher in CBC mode.

View Source
var DefaultOpts = Opts{
	Cipher:     AES256CBC,
	KeyEncrypt: KeyEncryptRSA,
}

默认配置

View Source
var ErrPSKNotProvided = errors.New("pkcs7: cannot encrypt content: PSK not provided")
View Source
var ErrUnsupportedEncryptionAlgorithm = errors.New("pkcs7: cannot encrypt content: only DES-CBC, AES-CBC, and AES-GCM supported")
View Source
var KeyEncryptRSA = KeyEncryptWithRsa{
	// contains filtered or unexported fields
}

KeyEncryptRSA

View Source
var KeyEncryptRSAESOAEP = KeyEncryptWithRsa{
	// contains filtered or unexported fields
}

KeyEncryptRSAESOAEP

View Source
var KeyEncryptRSASHA1 = KeyEncryptWithRsa{
	// contains filtered or unexported fields
}

KeyEncryptRSASHA1

View Source
var KeyEncryptRSASHA256 = KeyEncryptWithRsa{
	// contains filtered or unexported fields
}

KeyEncryptRSASHA256

View Source
var KeyEncryptRSASHA384 = KeyEncryptWithRsa{
	// contains filtered or unexported fields
}

KeyEncryptRSASHA384

View Source
var KeyEncryptRSASHA512 = KeyEncryptWithRsa{
	// contains filtered or unexported fields
}

KeyEncryptRSASHA512

View Source
var KeyEncryptSM2 = KeyEncryptWithSM2{
	// contains filtered or unexported fields
}

KeyEncryptSM2

View Source
var SM4CBC = CipherCBC{
	// contains filtered or unexported fields
}

SM4CBC is the 128-bit key SM4 cipher in CBC mode.

View Source
var SM4CCM = CipherCCM{
	// contains filtered or unexported fields
}

SM4CCM is the 128-bit key SM4 cipher in CCM mode.

View Source
var SM4CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

SM4CCM is the 128-bit key SM4 cipher in CCM mode.

View Source
var SM4CFB = CipherCFB{
	// contains filtered or unexported fields
}

SM4CFB is the 128-bit key SM4 cipher in CFB mode.

View Source
var SM4CFB8 = CipherCFB8{
	// contains filtered or unexported fields
}

SM4CFB8 is the 128-bit key SM4 cipher in CFB mode.

View Source
var SM4ECB = CipherECB{
	// contains filtered or unexported fields
}

SM4ECB is the 128-bit key SM4 cipher in ECB mode.

View Source
var SM4GCM = CipherGCM{
	// contains filtered or unexported fields
}

SM4GCM is the 128-bit key SM4 cipher in GCM mode.

View Source
var SM4GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

SM4GCMb is the 128-bit key SM4 cipher in GCM mode.

View Source
var SM4OFB = CipherOFB{
	// contains filtered or unexported fields
}

SM4OFB is the 128-bit key SM4 cipher in OFB mode.

Functions

func AddCipher

func AddCipher(oid asn1.ObjectIdentifier, cipher func() Cipher)

添加加密

func AddkeyEncrypt

func AddkeyEncrypt(oid asn1.ObjectIdentifier, fn func() KeyEncrypt)

添加 key 加密方式

func Decrypt

func Decrypt(data []byte, cert *x509.Certificate, pkey crypto.PrivateKey) ([]byte, error)

解析

func DecryptUsingPSK

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

DecryptUsingPSK decrypts encrypted data using caller provided pre-shared secret

func Encrypt

func Encrypt(content []byte, recipients []*x509.Certificate, opts ...Opts) ([]byte, error)

加密

func EncryptUsingPSK

func EncryptUsingPSK(content []byte, key []byte, cipher Cipher) ([]byte, error)

EncryptUsingPSK creates and returns an encrypted data PKCS7 structure, encrypted using caller provided pre-shared secret.

Types

type Cipher

type Cipher interface {
	// oid
	OID() asn1.ObjectIdentifier

	// 值大小
	KeySize() int

	// 加密, 返回: [加密后数据, 参数, error]
	Encrypt(key, plaintext []byte) ([]byte, []byte, error)

	// 解密
	Decrypt(key, params, ciphertext []byte) ([]byte, error)
}

加密接口

type CipherCBC

type CipherCBC struct {
	// contains filtered or unexported fields
}

cbc 模式加密

func (CipherCBC) Decrypt

func (this CipherCBC) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCBC) Encrypt

func (this CipherCBC) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherCBC) KeySize

func (this CipherCBC) KeySize() int

值大小

func (CipherCBC) OID

func (this CipherCBC) OID() asn1.ObjectIdentifier

oid

type CipherCCM

type CipherCCM struct {
	// contains filtered or unexported fields
}

ccm 模式加密

func (CipherCCM) Decrypt

func (this CipherCCM) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherCCM) Encrypt

func (this CipherCCM) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherCCM) KeySize

func (this CipherCCM) KeySize() int

值大小

func (CipherCCM) OID

func (this CipherCCM) OID() asn1.ObjectIdentifier

oid

type CipherCCMb

type CipherCCMb struct {
	// contains filtered or unexported fields
}

ccm 模式加密

func (CipherCCMb) Decrypt

func (this CipherCCMb) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherCCMb) Encrypt

func (this CipherCCMb) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherCCMb) KeySize

func (this CipherCCMb) KeySize() int

值大小

func (CipherCCMb) OID

func (this CipherCCMb) OID() asn1.ObjectIdentifier

oid

type CipherCFB

type CipherCFB struct {
	// contains filtered or unexported fields
}

CFB 模式加密

func (CipherCFB) Decrypt

func (this CipherCFB) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCFB) Encrypt

func (this CipherCFB) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherCFB) KeySize

func (this CipherCFB) KeySize() int

值大小

func (CipherCFB) OID

func (this CipherCFB) OID() asn1.ObjectIdentifier

oid

type CipherCFB8

type CipherCFB8 struct {
	// contains filtered or unexported fields
}

CFB8 模式加密

func (CipherCFB8) Decrypt

func (this CipherCFB8) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCFB8) Encrypt

func (this CipherCFB8) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherCFB8) KeySize

func (this CipherCFB8) KeySize() int

值大小

func (CipherCFB8) OID

func (this CipherCFB8) OID() asn1.ObjectIdentifier

oid

type CipherECB

type CipherECB struct {
	// contains filtered or unexported fields
}

ecb 模式加密

func (CipherECB) Decrypt

func (this CipherECB) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherECB) Encrypt

func (this CipherECB) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherECB) KeySize

func (this CipherECB) KeySize() int

值大小

func (CipherECB) OID

func (this CipherECB) OID() asn1.ObjectIdentifier

oid

type CipherGCM

type CipherGCM struct {
	// contains filtered or unexported fields
}

gcm 模式加密

func (CipherGCM) Decrypt

func (this CipherGCM) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherGCM) Encrypt

func (this CipherGCM) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherGCM) KeySize

func (this CipherGCM) KeySize() int

值大小

func (CipherGCM) OID

func (this CipherGCM) OID() asn1.ObjectIdentifier

oid

type CipherGCMb

type CipherGCMb struct {
	// contains filtered or unexported fields
}

gcm 模式加密

func (CipherGCMb) Decrypt

func (this CipherGCMb) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherGCMb) Encrypt

func (this CipherGCMb) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherGCMb) KeySize

func (this CipherGCMb) KeySize() int

值大小

func (CipherGCMb) OID

func (this CipherGCMb) OID() asn1.ObjectIdentifier

oid

type CipherOFB

type CipherOFB struct {
	// contains filtered or unexported fields
}

OFB 模式加密

func (CipherOFB) Decrypt

func (this CipherOFB) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherOFB) Encrypt

func (this CipherOFB) Encrypt(key, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherOFB) KeySize

func (this CipherOFB) KeySize() int

值大小

func (CipherOFB) OID

func (this CipherOFB) OID() asn1.ObjectIdentifier

oid

type KeyEncrypt

type KeyEncrypt interface {
	// oid
	OID() asn1.ObjectIdentifier

	// 加密, 返回: [加密后数据, error]
	Encrypt(plaintext []byte, pkey crypto.PublicKey) ([]byte, error)

	// 解密
	Decrypt(ciphertext []byte, pkey crypto.PrivateKey) ([]byte, error)
}

非对称加密

type KeyEncryptWithRsa

type KeyEncryptWithRsa struct {
	// contains filtered or unexported fields
}

key 用 rsa 加密

func (KeyEncryptWithRsa) Decrypt

func (this KeyEncryptWithRsa) Decrypt(ciphertext []byte, pkey crypto.PrivateKey) ([]byte, error)

解密

func (KeyEncryptWithRsa) Encrypt

func (this KeyEncryptWithRsa) Encrypt(plaintext []byte, pkey crypto.PublicKey) ([]byte, error)

加密

func (KeyEncryptWithRsa) OID

oid

type KeyEncryptWithSM2

type KeyEncryptWithSM2 struct {
	// contains filtered or unexported fields
}

key 用 sm2 加密

func (KeyEncryptWithSM2) Decrypt

func (this KeyEncryptWithSM2) Decrypt(ciphertext []byte, pkey crypto.PrivateKey) ([]byte, error)

解密

func (KeyEncryptWithSM2) Encrypt

func (this KeyEncryptWithSM2) Encrypt(plaintext []byte, pkey crypto.PublicKey) ([]byte, error)

加密

func (KeyEncryptWithSM2) OID

oid

type Opts

type Opts struct {
	Cipher     Cipher
	KeyEncrypt KeyEncrypt
}

配置

Jump to

Keyboard shortcuts

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