> For the complete documentation index, see [llms.txt](https://docs.safle.com/safleid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.safle.com/safleid/safle-vault/encryption-decryption-module.md).

# Encryption/Decryption Module

### **Encryption Sequence**

1. User selects a SafleID and password(plain text password)
2. Client application generates a random 64 bytes string. This is stored as encryption key.
3. Client application generates PDKey using safleID & password using pbkdf2 algorithm
4. Client application hashes PDKey using SHA512
5. Client application encrypts encryption key using PDKey using aes.cbc algorithm
6. Client application hashes plain password using PDKey using pbkdf2 algorithm
7. Send encrypted encryption key, hashed password and PDKeyHash to server

### **Encryption Sequence extended for safle vault**

All the private functions which access the private keys are securitised using the user's PIN. Further, the entire vault is encrypted again using an `encryptionKey` which is a hash of the user's safleId and password.

1. User enters a 6 digit pin on client app
2. Generate vault using vault SDK
3. Client encrypts private data of vault using pin using aes.encrypt method. This is the locked vault.
4. Encrypt complete vault object using encryption key. This returns vault string
5. Save vault to mobile app keyring\ <br>

   <figure><img src="/files/ryAp9dTiOMAmSDJ4wDgI" alt=""><figcaption></figcaption></figure>

<mark style="color:yellow;">`💡All the encryption and decryption is done at the client-side to ensure security and to make the user's wallet and funds truly non-custodial.`</mark>
