cryptostream

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(data []byte) ([]byte, error)

Compress compresses the input data using Snappy and returns the compressed data or an error.

func Decompress

func Decompress(compressedData []byte) ([]byte, error)

Decompress decompresses the input Snappy-compressed data and returns the original data or an error.

func PKCS7Pad

func PKCS7Pad(data []byte, blockSize int) []byte

Types

type AesCtrEncryptor

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

AesCtrEncryptor struct holding key, iv, and separate streams for encryption and decryption

func NewAesCtrEncryptor

func NewAesCtrEncryptor(key [32]byte, iv [16]byte) (*AesCtrEncryptor, error)

NewAesCtrEncryptor creates a new instance of AesCtrEncryptor

func (*AesCtrEncryptor) Decrypt

func (e *AesCtrEncryptor) Decrypt(reader io.Reader, writer io.Writer) error

Decrypt decrypts data using AES-256-CTR mode

func (*AesCtrEncryptor) Encrypt

func (e *AesCtrEncryptor) Encrypt(reader io.Reader, writer io.Writer) error

Encrypt encrypts data using AES-256-CTR mode

func (*AesCtrEncryptor) Reset

func (e *AesCtrEncryptor) Reset() error

Reset reinitializes the encrypt and decrypt streams

type CryptoConn

type CryptoConn struct {
	net.Conn

	Cryptor
}

func NewCryptoConn

func NewCryptoConn(conn net.Conn, cryptor Cryptor) *CryptoConn

func (*CryptoConn) Read

func (sc *CryptoConn) Read(data []byte) (int, error)

Read 方法从底层连接读取数据并解密

func (*CryptoConn) Write

func (sc *CryptoConn) Write(data []byte) (int, error)

type Cryptor

type Cryptor interface {
	Encrypt(reader io.Reader, writer io.Writer) error
	Decrypt(reader io.Reader, writer io.Writer) error
	Reset() error
}

func NewCryptor

func NewCryptor(name string, key, secret []byte) (Cryptor, error)

type XorEncryptor

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

XorEncryptor struct holding key, iv, and separate counters for encryption and decryption

func NewXorEncryptor

func NewXorEncryptor(key []byte, iv []byte) *XorEncryptor

NewXorEncryptor creates a new instance of XorEncryptor

func (*XorEncryptor) Decrypt

func (e *XorEncryptor) Decrypt(reader io.Reader, writer io.Writer) error

Decrypt reads data from reader, applies XOR decryption, and writes it to writer

func (*XorEncryptor) Encrypt

func (e *XorEncryptor) Encrypt(reader io.Reader, writer io.Writer) error

Encrypt reads data from reader, applies XOR encryption, and writes it to writer

func (*XorEncryptor) Reset

func (e *XorEncryptor) Reset() error

Reset resets both the encryption and decryption counters

Jump to

Keyboard shortcuts

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