> For the complete documentation index, see [llms.txt](https://0xn3va.gitbook.io/application-security-handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xn3va.gitbook.io/application-security-handbook/web-application/cryptography.md).

# Cryptography

## Overview

This section contains recommendations for implementing and using functionality related to cryptographic operations.

{% hint style="warning" %}
Main rule of cryptography is do **not** invent your own cryptography. It can definitely be hacked.
{% endhint %}

## General practices

| Scenario              | Algorithm (base)                      | Algorithm (advanced)                     |
| --------------------- | ------------------------------------- | ---------------------------------------- |
| Key exchange          | Diffie-Hellman key exchange, 2048 bit | ECDH Curve25519                          |
| Message integrity     | HMAC-SHA2, 256 bit                    | HMAC-SHA2, 512 bit                       |
| Message hash          | SHA2, 256 bit                         | SHA2, 512 bit                            |
| Asymmetric encryption | RSA, 2048 bit, SHA-256                | ECC Curve25519 or RSA, 3072 bit, SHA-256 |
| Symmetric encryption  | AES, 128 bit, GCM                     | AES, 256 bit, GCM                        |
| Key exchange          | Argon2 or PBKDF2                      | Argon2 or PBKDF2                         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://0xn3va.gitbook.io/application-security-handbook/web-application/cryptography.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
