crypto

package
v0.0.0-...-c788b61 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RsaCryptoWrap    string = "RSA/NONE/PKCS1Padding"
	KmsAliCryptoWrap string = "KMS/ALICLOUD"
	AesCtrAlgorithm  string = "AES/CTR/NoPadding"
)

encryption Algorithm

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

type Cipher interface {
	Encrypter
	Decrypter
}

Cipher is interface for encryption or decryption of an object

type CipherData

type CipherData struct {
	IV            []byte
	Key           []byte
	MatDesc       string
	WrapAlgorithm string
	CEKAlgorithm  string
	EncryptedIV   []byte
	EncryptedKey  []byte
}

CipherData is secret key information

func (*CipherData) Clone

func (cd *CipherData) Clone() CipherData

func (*CipherData) GetIV

func (cd *CipherData) GetIV() uint64

func (*CipherData) RandomKeyIv

func (cd *CipherData) RandomKeyIv(keyLen int, ivLen int) error

func (*CipherData) SeekIV

func (cd *CipherData) SeekIV(startPos uint64)

func (*CipherData) SetIV

func (cd *CipherData) SetIV(iv uint64)

type ContentCipher

type ContentCipher interface {
	EncryptContent(io.Reader) (io.ReadCloser, error)
	DecryptContent(io.Reader) (io.ReadCloser, error)
	Clone(cd CipherData) (ContentCipher, error)
	GetEncryptedLen(int64) int64
	GetCipherData() *CipherData
	GetAlignLen() int
}

ContentCipher is used to encrypt or decrypt object's data

type ContentCipherBuilder

type ContentCipherBuilder interface {
	ContentCipher() (ContentCipher, error)
	ContentCipherEnv(Envelope) (ContentCipher, error)
	GetMatDesc() string
}

ContentCipherBuilder is used to create ContentCipher for encryting object's data

func CreateAesCtrCipher

func CreateAesCtrCipher(cipher MasterCipher) ContentCipherBuilder

CreateAesCtrCipher creates ContentCipherBuilder

type CryptoDecrypter

type CryptoDecrypter struct {
	Body      io.Reader
	Decrypter io.Reader
	// contains filtered or unexported fields
}

CryptoDecrypter provides close method for Decrypter

func (*CryptoDecrypter) Close

func (rc *CryptoDecrypter) Close() error

Close lets the CryptoDecrypter satisfy io.ReadCloser interface

func (*CryptoDecrypter) Read

func (rc *CryptoDecrypter) Read(b []byte) (int, error)

Read lets the CryptoDecrypter satisfy io.ReadCloser interface

type CryptoEncrypter

type CryptoEncrypter struct {
	Body      io.Reader
	Encrypter io.Reader
	// contains filtered or unexported fields
}

CryptoEncrypter provides close method for Encrypter

func (*CryptoEncrypter) Close

func (rc *CryptoEncrypter) Close() error

Close lets the CryptoEncrypter satisfy io.ReadCloser interface

func (*CryptoEncrypter) Read

func (rc *CryptoEncrypter) Read(b []byte) (int, error)

Read lets the CryptoEncrypter satisfy io.ReadCloser interface

type Decrypter

type Decrypter interface {
	Decrypt(io.Reader) io.Reader
}

Decrypter is interface with only decrypt method

type Encrypter

type Encrypter interface {
	Encrypt(io.Reader) io.Reader
}

Encrypter is interface with only encrypt method

type Envelope

type Envelope struct {
	IV                    string
	CipherKey             string
	MatDesc               string
	WrapAlg               string
	CEKAlg                string
	UnencryptedMD5        string
	UnencryptedContentLen string
}

Envelope is stored in oss object's meta

func (Envelope) IsValid

func (el Envelope) IsValid() bool

func (Envelope) String

func (el Envelope) String() string

type MasterCipher

type MasterCipher interface {
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)
	GetWrapAlgorithm() string
	GetMatDesc() string
}

MasterCipher encrypt or decrpt CipherData support master key: rsa && ali kms

func CreateMasterRsa

func CreateMasterRsa(matDesc map[string]string, publicKey string, privateKey string) (MasterCipher, error)

CreateMasterRsa Create master key interface implemented by rsa matDesc will be converted to json string

type MasterRsaCipher

type MasterRsaCipher struct {
	MatDesc    string
	PublicKey  string
	PrivateKey string
}

MasterRsaCipher rsa master key interface

func (MasterRsaCipher) Decrypt

func (mrc MasterRsaCipher) Decrypt(cryptoData []byte) ([]byte, error)

Decrypt Decrypt data by rsa private key Mainly used to decrypt object's symmetric secret key and iv

func (MasterRsaCipher) Encrypt

func (mrc MasterRsaCipher) Encrypt(plainData []byte) ([]byte, error)

Encrypt encrypt data by rsa public key Mainly used to encrypt object's symmetric secret key and iv

func (MasterRsaCipher) GetMatDesc

func (mrc MasterRsaCipher) GetMatDesc() string

GetMatDesc get master key describe

func (MasterRsaCipher) GetWrapAlgorithm

func (mrc MasterRsaCipher) GetWrapAlgorithm() string

GetWrapAlgorithm get master key wrap algorithm

Jump to

Keyboard shortcuts

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