Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidKeySize indicates the AES key is not 16, 24, or 32 bytes ErrInvalidKeySize = oops.Errorf("invalid AES key size: must be 16, 24, or 32 bytes") // ErrInvalidIVSize indicates the AES IV is not 16 bytes ErrInvalidIVSize = oops.Errorf("invalid AES IV size: must be 16 bytes") )
Error definitions for AES operations
Functions ¶
Types ¶
type AESSymmetricDecrypter ¶
AESSymmetricDecrypter implements the Decrypter interface using AES
func (*AESSymmetricDecrypter) Decrypt ¶
func (d *AESSymmetricDecrypter) Decrypt(data []byte) ([]byte, error)
Decrypt decrypts data using AES-CBC with PKCS#7 padding
func (*AESSymmetricDecrypter) DecryptNoPadding ¶
func (d *AESSymmetricDecrypter) DecryptNoPadding(data []byte) ([]byte, error)
DecryptNoPadding decrypts data using AES-CBC without padding
type AESSymmetricEncrypter ¶
AESSymmetricEncrypter implements the Encrypter interface using AES
func (*AESSymmetricEncrypter) Encrypt ¶
func (e *AESSymmetricEncrypter) Encrypt(data []byte) ([]byte, error)
Encrypt encrypts data using AES-CBC with PKCS#7 padding
func (*AESSymmetricEncrypter) EncryptNoPadding ¶
func (e *AESSymmetricEncrypter) EncryptNoPadding(data []byte) ([]byte, error)
EncryptNoPadding encrypts data using AES-CBC without padding
type AESSymmetricKey ¶
type AESSymmetricKey struct {
Key []byte // AES key (must be 16, 24, or 32 bytes for AES-128, AES-192, AES-256)
IV []byte // Initialization Vector (must be 16 bytes for AES)
}
AESSymmetricKey represents a symmetric key for AES encryption/decryption.
CRITICAL: Never create AESSymmetricKey using zero-value construction or direct struct literals. Zero-value construction results in nil slices which:
- Will panic when calling NewEncrypter() or NewDecrypter()
- Violates AES security requirements
- Cannot be detected until runtime
ALWAYS use NewAESKey() or variant constructors for safe construction.
WRONG - Will panic:
var key AESSymmetricKey // nil slices - will panic!
key := AESSymmetricKey{...} // no validation
CORRECT - Use constructor:
key, err := aes.NewAESKey(keyBytes, ivBytes)
if err != nil {
return err
}
defer key.Zero() // Always zero sensitive key material
func NewAES128Key ¶ added in v0.1.0
func NewAES128Key(key, iv []byte) (*AESSymmetricKey, error)
NewAES128Key is a convenience constructor for AES-128 keys.
Parameters:
- key: Must be exactly 16 bytes
- iv: Must be exactly 16 bytes
Returns an error if sizes are invalid.
func NewAES192Key ¶ added in v0.1.0
func NewAES192Key(key, iv []byte) (*AESSymmetricKey, error)
NewAES192Key is a convenience constructor for AES-192 keys.
Parameters:
- key: Must be exactly 24 bytes
- iv: Must be exactly 16 bytes
Returns an error if sizes are invalid.
func NewAES256Key ¶ added in v0.1.0
func NewAES256Key(key, iv []byte) (*AESSymmetricKey, error)
NewAES256Key is a convenience constructor for AES-256 keys. AES-256 provides the strongest security level and is recommended for most use cases.
Parameters:
- key: Must be exactly 32 bytes
- iv: Must be exactly 16 bytes
Returns an error if sizes are invalid.
Example usage:
key, err := aes.NewAES256Key(keyBytes, ivBytes)
if err != nil {
return err
}
defer key.Zero()
func NewAESKey ¶ added in v0.1.0
func NewAESKey(key, iv []byte) (*AESSymmetricKey, error)
NewAESKey creates a validated AES symmetric key with IV.
This constructor provides mandatory validation to prevent common security issues:
- Rejects keys that are not 16, 24, or 32 bytes (AES-128/192/256)
- Rejects IVs that are not exactly 16 bytes
- Returns defensive copies to prevent external mutation
Parameters:
- key: Must be 16, 24, or 32 bytes for AES-128/192/256
- iv: Must be exactly 16 bytes
Returns an error if:
- Key size is invalid
- IV size is invalid
Example usage:
key, err := aes.NewAESKey(keyBytes, ivBytes)
if err != nil {
return err
}
defer key.Zero()
func (*AESSymmetricKey) NewDecrypter ¶
func (k *AESSymmetricKey) NewDecrypter() (types.Decrypter, error)
NewDecrypter creates a new AESSymmetricDecrypter
func (*AESSymmetricKey) NewEncrypter ¶
func (k *AESSymmetricKey) NewEncrypter() (types.Encrypter, error)
NewEncrypter creates a new AESSymmetricEncrypter
func (*AESSymmetricKey) Zero ¶
func (k *AESSymmetricKey) Zero()
Zero implements secure memory cleanup for sensitive key material. Clears both the AES key and IV from memory.