aesx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrCiphertextTooShort = errors.New("aesx: ciphertext too short")

ErrCiphertextTooShort is returned when GCM input is shorter than nonce plus tag.

View Source
var ErrInvalidCiphertext = errors.New("aesx: invalid ciphertext length")

ErrInvalidCiphertext is returned when CBC ciphertext length is not a positive multiple of the block size.

View Source
var ErrInvalidIV = errors.New("aesx: IV must be 16 bytes")

ErrInvalidIV is returned when the CBC IV length is not the AES block size.

View Source
var ErrInvalidPadding = errors.New("aesx: invalid PKCS7 padding")

ErrInvalidPadding is returned when PKCS#7 padding is malformed.

Functions

func CBCDecryptWithIV

func CBCDecryptWithIV(iv, key, cipherText string) (string, error)

CBCDecryptWithIV decrypts base64 ciphertext using base64-encoded iv and key. It returns an error if the padding is invalid.

func CBCEncryptWithIV

func CBCEncryptWithIV(iv, key, plainText string) (string, error)

CBCEncryptWithIV encrypts plainText using base64-encoded iv and key and returns base64 ciphertext.

func GCMDecrypt

func GCMDecrypt(key, ciphertext []byte) ([]byte, error)

GCMDecrypt decrypts data produced by GCMEncrypt and verifies the authentication tag.

func GCMDecryptString

func GCMDecryptString(key []byte, cipherText string) (string, error)

GCMDecryptString decrypts base64(nonce || ciphertext || tag) produced by GCMEncryptString.

func GCMEncrypt

func GCMEncrypt(key, plaintext []byte) ([]byte, error)

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

func GCMEncryptString(key []byte, plainText string) (string, error)

GCMEncryptString encrypts plainText and returns base64(nonce || ciphertext || tag).

func PKCS7Padding

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

PKCS7Padding applies PKCS#7 padding to data for the given block size. The input slice is not modified.

func PKCS7UnPadding

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

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.

Jump to

Keyboard shortcuts

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