---
title: Encryption
project: Total.js V5
version: 0.0.20
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/guides/encryption/
updated: 2026-11-16T15:32:32.495Z
---

# Encryption

> Encrypt values with ENCRYPT() and DECRYPT(), bind them to the client of a request with ENCRYPTREQ() and DECRYPTREQ(), and choose the cipher.

`ENCRYPT(value, key)` turns any JSON-serializable value into a string and `DECRYPT(string, key)` turns it back, or returns `null` for an invalid string. The secret `CONF.secret` is part of the key.

```js
var token = ENCRYPT({ id: user.id, expire: NOW.add('1 day') }, 'reset');
var data = DECRYPT(token, 'reset');
```

`ENCRYPTREQ($, value, key)` and `DECRYPTREQ($, value, key)` bind the value to the browser of the request (a hash of `User-Agent`, and the IP address with `strict`), so a token copied to another client does not decrypt:

```js
var token = ENCRYPTREQ($, { id: user.id }, 'download');
// later, in another request of the same browser
var data = DECRYPTREQ($, token, 'download');
```

To use a Node.js cipher instead of the built-in algorithm, set `$crypto` in the configuration (for example `aes-256-cbc`). The key then must have the byte length the cipher needs.
