Documentation
¶
Overview ¶
Package aes provides the AES encryption and decryption
Index ¶
- func DecodeCBCBase64(data string, key []byte) ([]byte, error)
- func DecryptCBC(crypted, key []byte) ([]byte, error)deprecated
- func DecryptGCM(data, key []byte) ([]byte, error)
- func EncodeCBCBase64(data, key []byte) (string, error)
- func EncryptCBC(data, key []byte) ([]byte, error)deprecated
- func EncryptGCM(data, key []byte) ([]byte, error)
- func PKCS5Padding(plaintext []byte, blockSize int) []byte
- func PKCS5UnPadding(data []byte) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeCBCBase64 ¶
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
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
DecryptGCM decrypts data that was encrypted using AES-GCM. It expects the nonce to be prepended to the ciphertext.
func EncodeCBCBase64 ¶
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
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
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 ¶
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 ¶
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.