Documentation
¶
Overview ¶
Package cipher provides cryptographic cipher configuration and base functionality. It supports various symmetric encryption algorithms with different block modes, padding schemes, and streaming capabilities for secure data encryption and decryption.
Index ¶
- type AesCipher
- func (c *AesCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *AesCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *AesCipher) SetAAD(aad []byte)
- func (c *AesCipher) SetIV(iv []byte)
- func (c *AesCipher) SetNonce(nonce []byte)
- func (c *AesCipher) SetPadding(padding PaddingMode)
- type BlockMode
- type BlowfishCipher
- func (c *BlowfishCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *BlowfishCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *BlowfishCipher) SetAAD(aad []byte)
- func (c *BlowfishCipher) SetIV(iv []byte)
- func (c *BlowfishCipher) SetNonce(nonce []byte)
- func (c *BlowfishCipher) SetPadding(padding PaddingMode)
- type ChaCha20Cipher
- type ChaCha20Poly1305Cipher
- type CreateCipherError
- type DesCipher
- func (c *DesCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *DesCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *DesCipher) SetAAD(aad []byte)
- func (c *DesCipher) SetIV(iv []byte)
- func (c *DesCipher) SetNonce(nonce []byte)
- func (c *DesCipher) SetPadding(padding PaddingMode)
- type EmptyIVError
- type EmptyNonceError
- type InvalidIVError
- type InvalidSrcError
- type NilBlockError
- type PaddingMode
- type Rc4Cipher
- type Salsa20Cipher
- type TeaCipher
- type TripleDesCipher
- func (c *TripleDesCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *TripleDesCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *TripleDesCipher) SetAAD(aad []byte)
- func (c *TripleDesCipher) SetIV(iv []byte)
- func (c *TripleDesCipher) SetNonce(nonce []byte)
- func (c *TripleDesCipher) SetPadding(padding PaddingMode)
- type TwofishCipher
- func (c *TwofishCipher) Decrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *TwofishCipher) Encrypt(src []byte, block cipher.Block) (dst []byte, err error)
- func (c *TwofishCipher) SetAAD(aad []byte)
- func (c *TwofishCipher) SetIV(iv []byte)
- func (c *TwofishCipher) SetNonce(nonce []byte)
- func (c *TwofishCipher) SetPadding(padding PaddingMode)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AesCipher ¶
type AesCipher struct {
// contains filtered or unexported fields
}
func (*AesCipher) Decrypt ¶ added in v1.1.1
func (*AesCipher) Encrypt ¶ added in v1.1.1
func (*AesCipher) SetPadding ¶
func (c *AesCipher) SetPadding(padding PaddingMode)
type BlockMode ¶
type BlockMode string
BlockMode represents the different block cipher modes of operation
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
}
func NewBlowfishCipher ¶
func NewBlowfishCipher(block BlockMode) (c *BlowfishCipher)
func (*BlowfishCipher) Decrypt ¶ added in v1.1.1
func (*BlowfishCipher) Encrypt ¶ added in v1.1.1
func (*BlowfishCipher) SetPadding ¶
func (c *BlowfishCipher) SetPadding(padding PaddingMode)
type ChaCha20Cipher ¶ added in v1.1.2
type ChaCha20Cipher struct {
Nonce []byte
// contains filtered or unexported fields
}
func NewChaCha20Cipher ¶ added in v1.1.2
func NewChaCha20Cipher() (c *ChaCha20Cipher)
func (*ChaCha20Cipher) SetNonce ¶ added in v1.1.2
func (c *ChaCha20Cipher) SetNonce(nonce []byte)
type ChaCha20Poly1305Cipher ¶ added in v1.1.2
type ChaCha20Poly1305Cipher struct {
Nonce []byte
AAD []byte
// contains filtered or unexported fields
}
func NewChaCha20Poly1305Cipher ¶ added in v1.1.2
func NewChaCha20Poly1305Cipher() (c *ChaCha20Poly1305Cipher)
func (*ChaCha20Poly1305Cipher) SetAAD ¶ added in v1.1.2
func (c *ChaCha20Poly1305Cipher) SetAAD(aad []byte)
func (*ChaCha20Poly1305Cipher) SetKey ¶ added in v1.1.2
func (c *ChaCha20Poly1305Cipher) SetKey(key []byte)
func (*ChaCha20Poly1305Cipher) SetNonce ¶ added in v1.1.2
func (c *ChaCha20Poly1305Cipher) SetNonce(nonce []byte)
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
}
func (*DesCipher) Decrypt ¶ added in v1.1.1
func (*DesCipher) Encrypt ¶ added in v1.1.1
func (*DesCipher) SetPadding ¶
func (c *DesCipher) SetPadding(padding PaddingMode)
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 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 InvalidSrcError ¶
type InvalidSrcError struct {
// contains filtered or unexported fields
}
InvalidSrcError represents an error when the source data length is invalid for the specified block cipher mode. This error occurs when the source data length is not a multiple of the block size, which is required for most block cipher operations.
func (InvalidSrcError) Error ¶
func (e InvalidSrcError) Error() string
Error returns a formatted error message describing the invalid source data length. The message includes the cipher mode, actual source length, and required block size.
type NilBlockError ¶
type NilBlockError struct {
// contains filtered or unexported fields
}
NilBlockError represents an error when the cipher block is nil. This error occurs when a nil cipher block is passed to encryption or decryption functions, which is not allowed for any cipher operation.
func (NilBlockError) Error ¶
func (e NilBlockError) Error() string
Error returns a formatted error message indicating that the cipher block cannot be nil for the specified cipher mode.
type PaddingMode ¶
type PaddingMode string
PaddingMode represents the different padding schemes available for block ciphers
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 )
Supported padding modes for block cipher operations
type Rc4Cipher ¶
type Rc4Cipher struct {
// contains filtered or unexported fields
}
type Salsa20Cipher ¶ added in v1.1.4
type Salsa20Cipher struct {
Nonce []byte // 8-byte nonce for Salsa20
// contains filtered or unexported fields
}
Salsa20Cipher represents a Salsa20 cipher configuration. 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 Salsa20 cipher instance.
func (*Salsa20Cipher) SetNonce ¶ added in v1.1.4
func (c *Salsa20Cipher) SetNonce(nonce []byte)
SetNonce sets the nonce for Salsa20 encryption/decryption. The nonce must be exactly 8 bytes for Salsa20.
type TripleDesCipher ¶
type TripleDesCipher struct {
// contains filtered or unexported fields
}
func New3DesCipher ¶
func New3DesCipher(block BlockMode) (c *TripleDesCipher)
func (*TripleDesCipher) Decrypt ¶ added in v1.1.1
func (*TripleDesCipher) Encrypt ¶ added in v1.1.1
func (*TripleDesCipher) SetPadding ¶
func (c *TripleDesCipher) SetPadding(padding PaddingMode)
type TwofishCipher ¶ added in v1.1.4
type TwofishCipher struct {
// contains filtered or unexported fields
}
func NewTwofishCipher ¶ added in v1.1.4
func NewTwofishCipher(block BlockMode) (c *TwofishCipher)
func (*TwofishCipher) Decrypt ¶ added in v1.1.4
func (*TwofishCipher) Encrypt ¶ added in v1.1.4
func (*TwofishCipher) SetPadding ¶ added in v1.1.4
func (c *TwofishCipher) SetPadding(padding PaddingMode)
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
- tea.go
- twofish.go