aes

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Overview

Package aes provides the AES encryption and decryption

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCBCBase64

func DecodeCBCBase64(data string, key []byte) ([]byte, error)

DecodeCBCBase64 decrypts the base64-encoded data using the provided key and returns the decrypted data.

Parameters: - data: the base64-encoded data to be decrypted (string) - key: the decryption key ([]byte)

Returns: - []byte: the decrypted data - error: an error if the decryption fails

func DecryptCBC deprecated

func DecryptCBC(crypted, key []byte) ([]byte, error)

DecryptCBC decrypts the given ciphertext using the provided key.

Deprecated: This function uses a static IV derived from the key, which is insecure. It is provided for compatibility with legacy systems (e.g., WeChat Pay) and should not be used for new encryption implementations. For secure decryption, use a function that supports random IVs, such as AES-GCM.

Parameters: - crypted: the ciphertext to be decrypted ([]byte) - key: the decryption key ([]byte)

Returns: - []byte: the decrypted data - error: an error if the decryption fails

func DecryptGCM added in v0.3.18

func DecryptGCM(data, key []byte) ([]byte, error)

DecryptGCM decrypts data that was encrypted using AES-GCM. It expects the nonce to be prepended to the ciphertext.

func EncodeCBCBase64

func EncodeCBCBase64(data, key []byte) (string, error)

EncodeCBCBase64 encrypts the given original data using the provided key and returns the encrypted data as a base64-encoded string.

Parameters: - data: the data to be encrypted ([]byte) - key: the encryption key ([]byte)

Returns: - string: the encrypted data as a base64-encoded string - error: an error if the encryption fails

func EncryptCBC deprecated

func EncryptCBC(data, key []byte) ([]byte, error)

EncryptCBC encrypts the given original data using the provided key using the AES encryption algorithm in CBC mode.

Deprecated: This function uses a static IV derived from the key, which is insecure. It is provided for compatibility with legacy systems (e.g., WeChat Pay) and should not be used for new encryption implementations. For secure encryption, use a function that supports random IVs, such as AES-GCM.

Parameters: - data: the data to be encrypted ([]byte) - key: the encryption key ([]byte)

Returns: - []byte: the encrypted data - error: an error if the encryption fails

func EncryptGCM added in v0.3.18

func EncryptGCM(data, key []byte) ([]byte, error)

EncryptGCM encrypts data using AES-GCM, a modern and secure authenticated encryption mode. It generates a random nonce, prepends it to the ciphertext, and returns the result. The key must be 16, 24, or 32 bytes long to select AES-128, AES-192, or AES-256.

func PKCS5Padding

func PKCS5Padding(plaintext []byte, blockSize int) []byte

PKCS5Padding adds padding to the plaintext based on the blockSize.

plaintext: The data to pad. blockSize: The block size used for padding. []byte: The padded plaintext.

func PKCS5UnPadding

func PKCS5UnPadding(data []byte) []byte

PKCS5UnPadding removes the padding from the given byte array.

Parameters: - data: the byte array to remove the padding from.

Returns: - []byte: the byte array with the padding removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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