> ## Documentation Index
> Fetch the complete documentation index at: https://docutrack-docs.icpitalia.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Cryptography

> Docutrack Cryptography

The creation of keys, encryption of documents and their decryption keys is done entirely on the client side.

The dapp uses different kinds of keys [(link to source code)](https://github.com/icp-hub-it/ic-docutrack/blob/main/frontend/src/frontend/src/lib/crypto.js):

* **Documents**: Symmetric **AES-GCM** secret key: used to encrypt and decrypt a document. This secret key is stored encrypted for one or several users in the user canister.
* **Users**:
  * **RSA-OAEP public key**: used to encrypt the symmetric AES secret key of a document the user should have access to. The public key for each registered user is stored in the **Orchestrator**.
    **RSA-OAEP private key**: used to decrypt the symmetric AES secret key of a document stored in the user canister. Once the frontend decrypts the secret key, it can use this key for decrypting the corresponding document stored in the backend. The private key never leaves the client-side and is not stored anywhere else.

For each user and for each document separate keys are being used.

<Frame>
  ![cryptography keys](https://github.com/icp-hub-it/ic-docutrack/raw/main/docs/images/crypto-keys.png)
</Frame>

In order for Alice to share Document 2 with Bob (who needs to have an II to support this functionality), the secret key of Document 2 needs to be encrypted for Bob’s public key.

<Frame>
  ![cryptography keys sharing](https://github.com/icp-hub-it/ic-docutrack/raw/main/docs/images/crypto-keys-sharing.png)
</Frame>

This key is then added to the **User Canister**.

<Frame>
  ![cryptography keys sharing in user canister](https://github.com/icp-hub-it/ic-docutrack/raw/main/docs/images/crypto-keys-sharing-in-user-canister.png)
</Frame>

Bob’s frontend can now download the document together with the document key encrypted for Bob and decrypt it locally.

<Frame>
  ![cryptography keys sharing in user canister](https://github.com/icp-hub-it/ic-docutrack/raw/main/docs/images/crypto-keys-sharing-in-user-canister2.png)
</Frame>
