> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/decrypt.md).

# Decrypt

Decrypts a provided encoded encrypted string using the specified algorithm and key

## Method Signature

```
Decrypt(string=[string], key=[string], algorithm=[string], encoding=[string], IVorSalt=[any], iterations=[integer], precise=[boolean])
```

### Arguments

| Argument     | Type      | Required | Description                                                                                                                    | Default |
| ------------ | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `string`     | `string`  | `true`   | The encrypted string to decrypt                                                                                                |         |
| `key`        | `string`  | `true`   | The string representation of the secret key to use for encryption ( see generateSecretKey() )                                  |         |
| `algorithm`  | `string`  | `false`  | The algorithm to use for encryption. Default is AES                                                                            |         |
| `encoding`   | `string`  | `false`  | The encoding type to use for encoding the encrypted data. Default is Base64                                                    | `UU`    |
| `IVorSalt`   | `any`     | `false`  | The initialization vector or salt to use for encryption.                                                                       |         |
| `iterations` | `integer` | `false`  | The number of iterations to use for encryption. Default is 1000                                                                | `1000`  |
| `precise`    | `boolean` | `false`  | If set to true, the string and key will be validated before encryption to ensure conformity to the algorithm. Default is false | `false` |

## Examples

### Encrypt and Decrypt a Secret

Generate an AES 128 bit key and then use it to encrypt and decrypt a secret.

[Run Example](https://try.boxlang.io/?code=eJxLrVCwVaiuteZKrdDzdo0EctJT81KLEktSg1OTi1JLvFMrNRSUHF2DlRQ0wYqCXZ2DXEOA6pRK8gsUisGKlMAyrn7OQZEBIa4uQMnUvOSiyoISDQW4Dh0FiA06ENOAlFNicaqZCcxcF1eE7pRUhG64qXgNKC%2FKLEl1Kc0tAOkBCQAA8t497g%3D%3D)

```java
ex = {};
ex.KEY = generateSecretKey( "AES" );
ex.SECRET = "top secret";
ex.ENCRYPTED = encrypt( ex.SECRET, ex.KEY, "AES", "Base64" );
ex.DECRYPTED = decrypt( ex.ENCRYPTED, ex.KEY, "AES", "Base64" );
writeDump( ex );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJzLTq1UsFVIT81LLUosSQ1OTS5KLfFOrdRQUHLy8Q938wz2UFLQtOYqSS0ucc1LLqosKAEqT4WwgIqKE9NS4%2FNLi%2BJLilJTlXQUslMrdZC0AtlJicWpZiZwQ1xSYYakpEINQTKbgAHlRZklqS6luQUQTTCzgDIAOTM%2FrQ%3D%3D)

```java
key = generateSecretKey( "BLOWFISH" );
testEncrypt = encrypt( "safe_our_tree", key, "BLOWFISH", "base64" );
testDecrypt = decrypt( testEncrypt, key, "BLOWFISH", "base64" );
writeDump( testDecrypt );

```

## Related

* [DecryptBinary](/boxlang-language/reference/built-in-functions/encryption/decryptbinary.md)
* [Encrypt](/boxlang-language/reference/built-in-functions/encryption/encrypt.md)
* [EncryptBinary](/boxlang-language/reference/built-in-functions/encryption/encryptbinary.md)
* [GeneratePBKDFKey](/boxlang-language/reference/built-in-functions/encryption/generatepbkdfkey.md)
* [GenerateSecretKey](/boxlang-language/reference/built-in-functions/encryption/generatesecretkey.md)
* [Hash](/boxlang-language/reference/built-in-functions/encryption/hash.md)
* [Hash40](/boxlang-language/reference/built-in-functions/encryption/hash40.md)
* [Hmac](/boxlang-language/reference/built-in-functions/encryption/hmac.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/decrypt.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
