# 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>


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.safle.com/safleid/safle-vault/encryption-decryption-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
