---
title: Les méthodes encrypt / decrypt
slug: oip-next/lztg9eovw7xpbgem0l22y
icon: {"lucideIcon":"📘"}
createdAt: 2024-05-29T13:10:32.000Z
---

Les méthodes `encrypt` / `decrypt` permettent d'encoder et de décoder une propriété d'une entité.

Signature :&#x20;

- `<T>(parentEntity: T, property: string) => T`
- `<T>(parentEntity: T, id: string, property: string) => T`

```javascript
let customer = await Entities('Customer').create();
let socialSecurity = await Entities('SocialSecurity').create();

customer = await Entities('SocialSecurity').save(customer, socialSecurity);

customer = await Entities('SocialSecurity').encrypt(customer, 'dateCSS');
customer = await Entities('SocialSecurity').decrypt(customer, 'dateCSS');
```

```javascript
let contact = await Entities('Contact').create();
let bankAccount1 = await Entities('BankAccount').create();
let bankAccount2 = await Entities('BankAccount').create();

contact = await Entities('BankAccount').save(contact, bankAccount1);
contact = await Entities('BankAccount').save(contact, bankAccount2);

contact = await Entities('BankAccount').encrypt(contact, bankAccount1.id, 'bankName');
contact = await Entities('BankAccount').decrypt(contact, bankAccount1.id, 'bankName');
```
