> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# aes_decrypt

> Uses the specified Advanced Encryption Standard (AES) algorithm and the encryption key to decrypt a string.

Uses the specified Advanced Encryption Standard (AES) algorithm and the encryption key to decrypt a string.

## Syntax

```Haskell theme={null}
aes_decrypt(str, key_str[, init_vector][, encryption_mode][, aad_str]);
```

## Parameters

* `str` (Required): the string to decrypt. It must be of the VARCHAR type.

* `key_str` (Required): the key used to encrypt `str`. It must be of the VARCHAR type.

* `init_vector` (Optional): Initialization Vector (IV): A crucial security parameter in AES encryption that ensures identical plaintexts yield distinct ciphertexts. It is only utilized in CBC, CFB, OFB, CTR, and GCM modes. It must be of the VARCHAR type.

* `encryption_mode` (Optional): The encryption algorithm. It must be of the VARCHAR type. Default value: `AES_128_ECB`.

  Supported algorithms:

  | ECB | CBC | CFB | CFB1 | CFB8 | CFB128 | OFB | CTR | GCM |
  | - | - | - | - | - | - | - | - | - |
  | AES\_128\_ECB | AES\_128\_CBC | AES\_128\_CFB | AES\_128\_CFB1 | AES\_128\_CFB8 | AES\_128\_CFB128 | AES\_128\_OFB | AES\_128\_CTR | AES\_128\_GCM |
  | AES\_192\_ECB | AES\_192\_CBC | AES\_192\_CFB | AES\_192\_CFB1 | AES\_192\_CFB8 | AES\_192\_CFB128 | AES\_192\_OFB | AES\_192\_CTR | AES\_192\_GCM |
  | AES\_256\_ECB | AES\_256\_CBC | AES\_256\_CFB | AES\_256\_CFB1 | AES\_256\_CFB8 | AES\_256\_CFB128 | AES\_256\_OFB | AES\_256\_CTR | AES\_256\_GCM |

* `aad_str` (Optional): Denotes Additional Authenticated Data (AAD). This is a parameter unique to authenticated encryption modes (e.g., GCM). It allows for including data that must be authenticated for integrity (preventing tampering) but does not require confidentiality (it remains unencrypted). It must be of the VARCHAR type.

## Return value

Returns a value of the VARCHAR type. If the input is invalid, NULL is returned.

## Examples

Decode a Base64 string and use this function to decrypt the decoded string into the original string.

```Plain Text theme={null}
mysql> select AES_DECRYPT(from_base64('uv/Lhzm74syo8JlfWarwKA==  '),'F3229A0B371ED2D9441B830D21A390C3');
+--------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('uv/Lhzm74syo8JlfWarwKA==  '), 'F3229A0B371ED2D9441B830D21A390C3') |
+--------------------------------------------------------------------------------------------+
| starrocks                                                                                  |
+--------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

```
mysql> select AES_DECRYPT(from_base64('uv/Lhzm74syo8JlfWarwKA=='),'F3229A0B371ED2D9441B830D21A390C3', NULL, "AES_128_ECB");
+---------------------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('uv/Lhzm74syo8JlfWarwKA=='), 'F3229A0B371ED2D9441B830D21A390C3', NULL, 'AES_128_ECB') |
+---------------------------------------------------------------------------------------------------------------+
| starrocks                                                                                                     |
+---------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

```
mysql> select AES_DECRYPT(from_base64('taXlwIvir9yff94F5Uv/KA=='),'F3229A0B371ED2D9441B830D21A390C3', "abcdefg", "AES_128_CBC");
+--------------------------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('taXlwIvir9yff94F5Uv/KA=='), 'F3229A0B371ED2D9441B830D21A390C3', 'abcdefg', 'AES_128_CBC') |
+--------------------------------------------------------------------------------------------------------------------+
| starrocks                                                                                                          |
+--------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

```
mysql> select AES_DECRYPT(from_base64('YWJjZGVmZ2hpamtsdpJC2rnrGmvqKQv/WcoO6NuOCXvUnC8pCw=='),'F3229A0B371ED2D9441B830D21A390C3', "abcdefghijklmnop", "AES_128_GCM", "abcdefg");
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('YWJjZGVmZ2hpamtsdpJC2rnrGmvqKQv/WcoO6NuOCXvUnC8pCw=='), 'F3229A0B371ED2D9441B830D21A390C3', 'abcdefghijklmnop', 'AES_128_GCM', 'abcdefg') |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| starrocks                                                                                                                                                          |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.