cipher

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cipher provides cryptographic cipher configuration and base functionality. It supports various symmetric encryption algorithms with different block modes, padding modes, and streaming capabilities for secure data encryption and decryption.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnsiX923Padding

func NewAnsiX923Padding(src []byte, blockSize int) []byte

NewAnsiX923Padding adds ANSI X.923 padding to the source data. ANSI X.923 padding fills with zeros and adds the padding length as the last byte. If the data length is already a multiple of block size, a full block of padding is added.

func NewAnsiX923UnPadding

func NewAnsiX923UnPadding(src []byte) []byte

NewAnsiX923UnPadding removes ANSI X.923 padding from the source data. This function validates that all padding bytes except the last are zero.

func NewBitPadding

func NewBitPadding(src []byte, blockSize int) []byte

NewBitPadding adds bit padding to the source data. Bit padding adds a 0x80 byte followed by zero bytes to reach the block size. This is similar to ISO9797-1 method 1 but with a different name.

func NewBitUnPadding

func NewBitUnPadding(src []byte) []byte

NewBitUnPadding removes bit padding from the source data. This function calls ISO9797-1 unpadding since they are identical.

func NewCBCDecrypter

func NewCBCDecrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewCBCDecrypter decrypts data using Cipher Block Chaining (CBC) mode. CBC decryption reverses the encryption process by applying the block cipher and then XORing with the previous ciphertext block.

func NewCBCEncrypter

func NewCBCEncrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewCBCEncrypter encrypts data using Cipher Block Chaining (CBC) mode. CBC mode encrypts each block of plaintext by XORing it with the previous ciphertext block before applying the block cipher algorithm.

func NewCFBDecrypter

func NewCFBDecrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewCFBDecrypter decrypts data using Cipher Feedback (CFB) mode. In CFB mode, decryption is identical to encryption since it's a stream cipher.

func NewCFBEncrypter

func NewCFBEncrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewCFBEncrypter encrypts data using Cipher Feedback (CFB) mode. CFB mode transforms a block cipher into a stream cipher by encrypting the previous ciphertext block and XORing the result with the plaintext.

func NewCTRDecrypter

func NewCTRDecrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewCTRDecrypter decrypts data using Counter (CTR) mode. In CTR mode, decryption is identical to encryption since it's a stream cipher.

func NewCTREncrypter

func NewCTREncrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewCTREncrypter encrypts data using Counter (CTR) mode. CTR mode transforms a block cipher into a stream cipher by encrypting a counter value and XORing the result with the plaintext.

func NewECBDecrypter

func NewECBDecrypter(src []byte, block cipher.Block) (dst []byte, err error)

NewECBDecrypter decrypts data using Electronic Codebook (ECB) mode. ECB decryption decrypts each block independently.

func NewECBEncrypter

func NewECBEncrypter(src []byte, block cipher.Block) (dst []byte, err error)

NewECBEncrypter encrypts data using Electronic Codebook (ECB) mode. ECB mode encrypts each block of plaintext independently using the same key. Note: ECB mode is generally not recommended for secure applications due to its vulnerability to pattern analysis.

func NewGCMDecrypter

func NewGCMDecrypter(src, nonce, aad []byte, block cipher.Block) (dst []byte, err error)

NewGCMDecrypter decrypts data using Galois/Counter Mode (GCM). GCM decryption verifies the authentication tag before decrypting the data.

func NewGCMEncrypter

func NewGCMEncrypter(src, nonce, aad []byte, block cipher.Block) (dst []byte, err error)

NewGCMEncrypter encrypts data using Galois/Counter Mode (GCM). GCM is an authenticated encryption mode that provides both confidentiality and authenticity. It combines CTR mode encryption with a Galois field multiplication for authentication.

func NewISO10126Padding

func NewISO10126Padding(src []byte, blockSize int) []byte

NewISO10126Padding adds ISO/IEC 10126 padding to the source data. ISO10126 padding fills with random bytes and adds the padding length as the last byte. This padding scheme provides better security by using random padding bytes.

func NewISO10126UnPadding

func NewISO10126UnPadding(src []byte) []byte

NewISO10126UnPadding removes ISO/IEC 10126 padding from the source data. This function reads the last byte to determine the padding size and removes that many bytes.

Note: The random padding bytes are not validated, only the length is used.

func NewISO78164Padding

func NewISO78164Padding(src []byte, blockSize int) []byte

NewISO78164Padding adds ISO/IEC 7816-4 padding to the source data. ISO7816-4 padding is identical to ISO9797-1 method 1 padding. This function calls ISO9797-1 padding implementation.

func NewISO78164UnPadding

func NewISO78164UnPadding(src []byte) []byte

NewISO78164UnPadding removes ISO/IEC 7816-4 padding from the source data. This function calls ISO9797-1 unpadding since they are identical.

func NewISO97971Padding

func NewISO97971Padding(src []byte, blockSize int) []byte

NewISO97971Padding adds ISO/IEC 9797-1 padding method 1 to the source data. ISO9797-1 method 1 adds a 0x80 byte followed by zero bytes to reach the block size. If the data length is already a multiple of block size, a full block of padding is added.

func NewISO97971UnPadding

func NewISO97971UnPadding(src []byte) []byte

NewISO97971UnPadding removes ISO/IEC 9797-1 padding method 1 from the source data. This function finds the last 0x80 byte and validates that all bytes after it are zero.

func NewNoPadding

func NewNoPadding(src []byte) []byte

NewNoPadding adds no padding to the source data. This function simply returns the original data without modification.

Note: Data must already be a multiple of the block size for this to work correctly.

func NewNoUnPadding

func NewNoUnPadding(src []byte) []byte

NewNoUnPadding removes no padding from the source data. This function simply returns the original data without modification.

func NewOFBDecrypter

func NewOFBDecrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewOFBDecrypter decrypts data using Output Feedback (OFB) mode. In OFB mode, decryption is identical to encryption since it's a stream cipher.

func NewOFBEncrypter

func NewOFBEncrypter(src, iv []byte, block cipher.Block) (dst []byte, err error)

NewOFBEncrypter encrypts data using Output Feedback (OFB) mode. OFB mode transforms a block cipher into a stream cipher by repeatedly encrypting the initialization vector and using the output as a keystream.

func NewPKCS5Padding

func NewPKCS5Padding(src []byte) []byte

NewPKCS5Padding adds PKCS5 padding to the source data. PKCS5 padding is identical to PKCS7 padding but is limited to 8-byte blocks. This function calls PKCS7 padding with a fixed block size of 8.

func NewPKCS5UnPadding

func NewPKCS5UnPadding(src []byte) []byte

NewPKCS5UnPadding removes PKCS5 padding from the source data. This function calls PKCS7 unpadding since PKCS5 and PKCS7 are identical.

func NewPKCS7Padding

func NewPKCS7Padding(src []byte, blockSize int) []byte

NewPKCS7Padding adds PKCS7 padding to the source data. PKCS7 padding adds N bytes, each with value N, where N is the number of padding bytes needed. This is the most commonly used padding scheme in modern cryptography.

func NewPKCS7UnPadding

func NewPKCS7UnPadding(src []byte) []byte

NewPKCS7UnPadding removes PKCS7 padding from the source data. This function reads the last byte to determine the padding size and removes that many bytes.

func NewTBCPadding added in v1.1.8

func NewTBCPadding(src []byte, blockSize int) []byte

NewTBCPadding adds TBC (Trailing Bit Complement) padding to the source data. TBC padding fills the padding bytes with 0x00 if the most significant bit (MSB) of the last data byte is 0; otherwise it fills with 0xFF. If the data length is already a multiple of block size, a full block of padding is added following the same rule.

func NewTBCUnPadding added in v1.1.8

func NewTBCUnPadding(src []byte) []byte

NewTBCUnPadding removes TBC padding from the source data by stripping all trailing bytes equal to the last byte value. This mirrors the ambiguity of zero padding removal and does not perform strict validation.

func NewZeroPadding

func NewZeroPadding(src []byte, blockSize int) []byte

NewZeroPadding adds zero padding to the source data. Zero padding adds padding bytes (filled with zeros) to reach the block size. If the data length is already a multiple of block size and not empty, no padding is added. Empty data always gets padded to a full block.

func NewZeroUnPadding

func NewZeroUnPadding(src []byte) []byte

NewZeroUnPadding removes zero padding from the source data. This function removes trailing zero bytes from the data.

Types

type AesCipher

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

AesCipher defines a AesCipher struct.

func NewAesCipher

func NewAesCipher(block BlockMode) *AesCipher

NewAesCipher returns a new AesCipher instance.

func (*AesCipher) Decrypt added in v1.1.1

func (c *AesCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*AesCipher) Encrypt added in v1.1.1

func (c *AesCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*AesCipher) SetAAD

func (c *AesCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*AesCipher) SetIV

func (c *AesCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*AesCipher) SetNonce

func (c *AesCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*AesCipher) SetPadding

func (c *AesCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

type BlockMode

type BlockMode string

BlockMode defines a BlockMode type.

const (
	CBC BlockMode = "CBC" // Cipher Block Chaining mode
	ECB BlockMode = "ECB" // Electronic Codebook mode
	CTR BlockMode = "CTR" // Counter mode
	GCM BlockMode = "GCM" // Galois/Counter Mode
	CFB BlockMode = "CFB" // Cipher Feedback mode
	OFB BlockMode = "OFB" // Output Feedback mode
)

Supported block cipher modes

type BlowfishCipher

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

BlowfishCipher defines a BlowfishCipher struct.

func NewBlowfishCipher

func NewBlowfishCipher(block BlockMode) *BlowfishCipher

NewBlowfishCipher returns a new BlowfishCipher instance.

func (*BlowfishCipher) Decrypt added in v1.1.1

func (c *BlowfishCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*BlowfishCipher) Encrypt added in v1.1.1

func (c *BlowfishCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*BlowfishCipher) SetAAD

func (c *BlowfishCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*BlowfishCipher) SetIV

func (c *BlowfishCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*BlowfishCipher) SetNonce

func (c *BlowfishCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*BlowfishCipher) SetPadding

func (c *BlowfishCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

type ChaCha20Cipher added in v1.1.2

type ChaCha20Cipher struct {
	Nonce []byte
	// contains filtered or unexported fields
}

ChaCha20Cipher defines a ChaCha20Cipher struct.

func NewChaCha20Cipher added in v1.1.2

func NewChaCha20Cipher() (c *ChaCha20Cipher)

NewChaCha20Cipher returns a new ChaCha20Cipher instance.

func (*ChaCha20Cipher) SetKey added in v1.1.2

func (c *ChaCha20Cipher) SetKey(key []byte)

SetKey sets the encryption key for the cipher.

func (*ChaCha20Cipher) SetNonce added in v1.1.2

func (c *ChaCha20Cipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

type ChaCha20Poly1305Cipher added in v1.1.2

type ChaCha20Poly1305Cipher struct {
	Nonce []byte
	AAD   []byte
	// contains filtered or unexported fields
}

ChaCha20Poly1305Cipher defines a ChaCha20Poly1305Cipher struct.

func NewChaCha20Poly1305Cipher added in v1.1.2

func NewChaCha20Poly1305Cipher() (c *ChaCha20Poly1305Cipher)

NewChaCha20Poly1305Cipher returns a new ChaCha20Poly1305Cipher instance.

func (*ChaCha20Poly1305Cipher) SetAAD added in v1.1.2

func (c *ChaCha20Poly1305Cipher) SetAAD(aad []byte)

SetAAD sets the additional authenticated data (AAD) for the cipher.

func (*ChaCha20Poly1305Cipher) SetKey added in v1.1.2

func (c *ChaCha20Poly1305Cipher) SetKey(key []byte)

SetKey sets the encryption key for the cipher.

func (*ChaCha20Poly1305Cipher) SetNonce added in v1.1.2

func (c *ChaCha20Poly1305Cipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

type CreateCipherError

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

CreateCipherError represents an error that occurs during cipher creation. This error wraps the underlying error that prevented the cipher from being created successfully, such as invalid key length or unsupported cipher mode.

func (CreateCipherError) Error

func (e CreateCipherError) Error() string

Error returns a formatted error message describing the cipher creation failure. The message includes the cipher mode and the underlying error details.

type DesCipher

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

DesCipher defines a DesCipher struct.

func NewDesCipher

func NewDesCipher(block BlockMode) *DesCipher

NewDesCipher returns a new DesCipher instance.

func (*DesCipher) Decrypt added in v1.1.1

func (c *DesCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*DesCipher) Encrypt added in v1.1.1

func (c *DesCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*DesCipher) SetAAD

func (c *DesCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*DesCipher) SetIV

func (c *DesCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*DesCipher) SetNonce

func (c *DesCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*DesCipher) SetPadding

func (c *DesCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

type EmptyIVError

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

EmptyIVError represents an error when the initialization vector (IV) is empty for cipher modes that require an IV. This error occurs when the IV is nil or has zero length, which is not allowed for secure cipher operations.

func (EmptyIVError) Error

func (e EmptyIVError) Error() string

Error returns a formatted error message indicating that the IV cannot be empty for the specified cipher mode.

type EmptyNonceError

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

EmptyNonceError represents an error when the nonce (number used once) is empty for cipher modes that require a nonce, such as GCM mode. This error occurs when the nonce is nil or has zero length, which is required for secure authenticated encryption.

func (EmptyNonceError) Error

func (e EmptyNonceError) Error() string

Error returns a formatted error message indicating that the nonce cannot be empty for the specified cipher mode.

type EmptySrcError added in v1.1.8

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

EmptySrcError represents an error when the source data is empty.

func (EmptySrcError) Error added in v1.1.8

func (e EmptySrcError) Error() string

Error returns a formatted error message indicating that the source cannot be empty for the specified cipher mode.

type InvalidCiphertextError added in v1.1.8

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

InvalidCiphertextError represents an error when the ciphertext length is invalid for the specified block cipher mode. This error occurs when the ciphertext length is not a multiple of the block size, which is required for most block cipher operations.

func (InvalidCiphertextError) Error added in v1.1.8

func (e InvalidCiphertextError) Error() string

Error returns a formatted error message describing the invalid ciphertext length. The message includes the ciphertext length, required block size, and cipher mode.

type InvalidIVError

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

InvalidIVError represents an error when the initialization vector (IV) length is invalid for the specified block cipher. This error occurs when the IV length does not match the required block size for the cipher.

func (InvalidIVError) Error

func (e InvalidIVError) Error() string

Error returns a formatted error message describing the invalid IV length. The message includes the cipher mode, actual IV length, and required block size.

type InvalidPlaintextError added in v1.1.8

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

InvalidPlaintextError represents an error when the plaintext length is invalid for the specified block cipher mode. This error occurs when the plaintext length is not a multiple of the block size, which is required for most block cipher operations.

func (InvalidPlaintextError) Error added in v1.1.8

func (e InvalidPlaintextError) Error() string

Error returns a formatted error message describing the invalid plaintext length. The message includes the cipher mode, actual plaintext length, and required block size.

type PaddingMode

type PaddingMode string

PaddingMode defines a PaddingMode type.

const (
	No       PaddingMode = "No"        // No padding - data must be exact block size
	Zero     PaddingMode = "Zero"      // Zero padding - fills with zeros, always adds padding
	PKCS5    PaddingMode = "PKCS5"     // PKCS5 padding - RFC 2898, 8-byte blocks only
	PKCS7    PaddingMode = "PKCS7"     // PKCS7 padding - RFC 5652, variable block size
	AnsiX923 PaddingMode = "AnsiX.923" // ANSI X.923 padding - zeros + length byte
	ISO97971 PaddingMode = "ISO9797-1" // ISO/IEC 9797-1 padding method 1
	ISO10126 PaddingMode = "ISO10126"  // ISO/IEC 10126 padding - random + length byte
	ISO78164 PaddingMode = "ISO7816-4" // ISO/IEC 7816-4 padding - same as ISO9797-1
	Bit      PaddingMode = "Bit"       // Bit padding - 0x80 + zeros
	TBC      PaddingMode = "TBC"       // TBC padding - 0x00 if last byte MSB=1, else 0xFF
)

Supported padding modes for block cipher operations

type Rc4Cipher

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

Rc4Cipher defines a Rc4Cipher struct.

func NewRc4Cipher

func NewRc4Cipher() (c *Rc4Cipher)

NewRc4Cipher returns a new Rc4Cipher instance.

func (*Rc4Cipher) SetKey

func (c *Rc4Cipher) SetKey(key []byte)

SetKey sets the encryption key for the cipher.

type Salsa20Cipher added in v1.1.4

type Salsa20Cipher struct {
	Nonce []byte // 8-byte nonce for Salsa20
	// contains filtered or unexported fields
}

Salsa20Cipher defines a Salsa20Cipher struct. Salsa20 is a stream cipher that uses a 32-byte key and 8-byte nonce.

func NewSalsa20Cipher added in v1.1.4

func NewSalsa20Cipher() *Salsa20Cipher

NewSalsa20Cipher creates a new Salsa20Cipher instance.

func (*Salsa20Cipher) SetKey added in v1.1.4

func (c *Salsa20Cipher) SetKey(key []byte)

SetKey sets the encryption key for the cipher.

func (*Salsa20Cipher) SetNonce added in v1.1.4

func (c *Salsa20Cipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher. The nonce must be exactly 8 bytes for Salsa20.

type Sm4Cipher added in v1.1.7

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

Sm4Cipher defines a Sm4Cipher struct.

func NewSm4Cipher added in v1.1.7

func NewSm4Cipher(block BlockMode) *Sm4Cipher

NewSm4Cipher returns a new Sm4Cipher instance.

func (*Sm4Cipher) Decrypt added in v1.1.7

func (c *Sm4Cipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*Sm4Cipher) Encrypt added in v1.1.7

func (c *Sm4Cipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*Sm4Cipher) SetAAD added in v1.1.7

func (c *Sm4Cipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*Sm4Cipher) SetIV added in v1.1.7

func (c *Sm4Cipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*Sm4Cipher) SetNonce added in v1.1.7

func (c *Sm4Cipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*Sm4Cipher) SetPadding added in v1.1.7

func (c *Sm4Cipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

type TeaCipher

type TeaCipher struct {
	Rounds int
	// contains filtered or unexported fields
}

TeaCipher defines a TeaCipher struct.

func NewTeaCipher

func NewTeaCipher(block BlockMode) *TeaCipher

NewTeaCipher returns a new TeaCipher instance.

func (*TeaCipher) Decrypt added in v1.1.6

func (c *TeaCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*TeaCipher) Encrypt added in v1.1.6

func (c *TeaCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*TeaCipher) SetAAD added in v1.1.6

func (c *TeaCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*TeaCipher) SetIV added in v1.1.6

func (c *TeaCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*TeaCipher) SetNonce added in v1.1.6

func (c *TeaCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*TeaCipher) SetPadding added in v1.1.6

func (c *TeaCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

func (*TeaCipher) SetRounds

func (c *TeaCipher) SetRounds(rounds int)

SetRounds sets the number of rounds for the cipher.

type TripleDesCipher

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

TripleDesCipher defines a TripleDesCipher struct.

func New3DesCipher

func New3DesCipher(block BlockMode) *TripleDesCipher

New3DesCipher returns a new TripleDesCipher instance.

func (*TripleDesCipher) Decrypt added in v1.1.1

func (c *TripleDesCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*TripleDesCipher) Encrypt added in v1.1.1

func (c *TripleDesCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*TripleDesCipher) SetAAD

func (c *TripleDesCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*TripleDesCipher) SetIV

func (c *TripleDesCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*TripleDesCipher) SetNonce

func (c *TripleDesCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*TripleDesCipher) SetPadding

func (c *TripleDesCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

type TwofishCipher added in v1.1.4

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

TwofishCipher defines a TwofishCipher struct.

func NewTwofishCipher added in v1.1.4

func NewTwofishCipher(block BlockMode) *TwofishCipher

NewTwofishCipher returns a new TwofishCipher instance.

func (*TwofishCipher) Decrypt added in v1.1.4

func (c *TwofishCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*TwofishCipher) Encrypt added in v1.1.4

func (c *TwofishCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*TwofishCipher) SetAAD added in v1.1.4

func (c *TwofishCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*TwofishCipher) SetIV added in v1.1.4

func (c *TwofishCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*TwofishCipher) SetNonce added in v1.1.4

func (c *TwofishCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*TwofishCipher) SetPadding added in v1.1.4

func (c *TwofishCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

type UnsupportedBlockModeError added in v1.1.7

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

UnsupportedBlockModeError represents an error when an unsupported block mode is used.

func (UnsupportedBlockModeError) Error added in v1.1.7

Error returns a formatted error message describing the unsupported mode. The message includes the mode name and explains why it's not supported.

type UnsupportedPaddingModeError added in v1.1.7

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

UnsupportedPaddingModeError represents an error when an unsupported padding mode is used.

func (UnsupportedPaddingModeError) Error added in v1.1.7

Error returns a formatted error message describing the unsupported padding mode. The message includes the mode name and explains why it's not supported.

type XteaCipher added in v1.1.6

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

XteaCipher defines a XteaCipher struct.

func NewXteaCipher added in v1.1.6

func NewXteaCipher(block BlockMode) *XteaCipher

NewXteaCipher returns a new XteaCipher instance.

func (*XteaCipher) Decrypt added in v1.1.6

func (c *XteaCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)

Decrypt decrypts the source data using the specified cipher.

func (*XteaCipher) Encrypt added in v1.1.6

func (c *XteaCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)

Encrypt encrypts the source data using the specified cipher.

func (*XteaCipher) SetAAD added in v1.1.6

func (c *XteaCipher) SetAAD(aad []byte)

SetAAD sets the additional authentication data (AAD) for the cipher.

func (*XteaCipher) SetIV added in v1.1.6

func (c *XteaCipher) SetIV(iv []byte)

SetIV sets the initialization vector (IV) for the cipher.

func (*XteaCipher) SetNonce added in v1.1.6

func (c *XteaCipher) SetNonce(nonce []byte)

SetNonce sets the nonce for the cipher.

func (*XteaCipher) SetPadding added in v1.1.6

func (c *XteaCipher) SetPadding(padding PaddingMode)

SetPadding sets the padding mode for the cipher.

Source Files

  • 3des.go
  • aes.go
  • block.go
  • blowfish.go
  • chacha20.go
  • chacha20poly1305.go
  • cipher.go
  • des.go
  • errors.go
  • padding.go
  • rc4.go
  • salsa20.go
  • sm4.go
  • tea.go
  • twofish.go
  • xtea.go

Jump to

Keyboard shortcuts

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