Documentation
¶
Overview ¶
Package aesx provides AES helpers: AES-GCM (preferred) and AES-CBC with an explicit IV.
ECB mode and CBC with the key reused as the IV are intentionally not provided. CBC offers no integrity protection; prefer GCMEncrypt / GCMDecrypt for new code.
Index ¶
- Variables
- func CBCDecryptWithIV(iv, key, cipherText string) (string, error)
- func CBCEncryptWithIV(iv, key, plainText string) (string, error)
- func GCMDecrypt(key, ciphertext []byte) ([]byte, error)
- func GCMDecryptString(key []byte, cipherText string) (string, error)
- func GCMEncrypt(key, plaintext []byte) ([]byte, error)
- func GCMEncryptString(key []byte, plainText string) (string, error)
- func PKCS7Padding(data []byte, blockSize int) []byte
- func PKCS7UnPadding(data []byte) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
var ErrCiphertextTooShort = errors.New("aesx: ciphertext too short")
ErrCiphertextTooShort is returned when GCM input is shorter than nonce plus tag.
var ErrInvalidCiphertext = errors.New("aesx: invalid ciphertext length")
ErrInvalidCiphertext is returned when CBC ciphertext length is not a positive multiple of the block size.
var ErrInvalidIV = errors.New("aesx: IV must be 16 bytes")
ErrInvalidIV is returned when the CBC IV length is not the AES block size.
var ErrInvalidPadding = errors.New("aesx: invalid PKCS7 padding")
ErrInvalidPadding is returned when PKCS#7 padding is malformed.
Functions ¶
func CBCDecryptWithIV ¶
CBCDecryptWithIV decrypts base64 ciphertext using base64-encoded iv and key. It returns an error if the padding is invalid.
func CBCEncryptWithIV ¶
CBCEncryptWithIV encrypts plainText using base64-encoded iv and key and returns base64 ciphertext.
func GCMDecrypt ¶
GCMDecrypt decrypts data produced by GCMEncrypt and verifies the authentication tag.
func GCMDecryptString ¶
GCMDecryptString decrypts base64(nonce || ciphertext || tag) produced by GCMEncryptString.
func GCMEncrypt ¶
GCMEncrypt encrypts plaintext with AES-GCM using a random nonce. The key must be 16, 24, or 32 bytes. Output layout: nonce || ciphertext || tag.
func GCMEncryptString ¶
GCMEncryptString encrypts plainText and returns base64(nonce || ciphertext || tag).
func PKCS7Padding ¶
PKCS7Padding applies PKCS#7 padding to data for the given block size. The input slice is not modified.
func PKCS7UnPadding ¶
PKCS7UnPadding removes PKCS#7 padding (AES block size) and returns an error when the padding is empty, out of range, or inconsistent.
Types ¶
This section is empty.