---
title: "Use only standard cryptography · Agent Wranglers"
url: https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets/standard-cryptography
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use only standard cryptography

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Data and secrets](https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- ID: SEC-104
- Level: Recommended
- Chapter: [Data and secrets](https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets)
- Rule: Encrypt and sign only with current algorithms from a maintained library. Never write your own scheme, and never use ECB mode, MD5 or SHA-1 for security.
- How: Encrypt with an authenticated mode, such as AES-256-GCM or ChaCha20-Poly1305, from a library such as libsodium or the platform's crypto module. Use a fresh random nonce for every message, never a fixed value or a counter that restarts. Sign and check messages with HMAC-SHA-256 or Ed25519. Field encryption follows [encrypt the most sensitive fields](https://agentwranglers.se/playbook/data/personal-data/field-encryption). Passwords take [a slow hash](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts/password-storage), and tokens take [a secure random source](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts/secure-random-tokens).
- Check: Search the code and settings for `md5`, `sha1`, `des`, `rc4`, `ecb` and hand-written XOR loops. No match encrypts data, signs a message or checks a token. Encrypt the same test value twice. The two results differ, and changing one byte of either makes decryption fail.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
import { createCipheriv, randomBytes } from 'node:crypto';

// Bad: ECB shows equal blocks for equal input, and nothing detects tampering
createCipheriv('aes-256-ecb', key, null);
// Good: GCM with a fresh nonce, and the tag stored with the text
const nonce = randomBytes(12);
const cipher = createCipheriv('aes-256-gcm', key, nonce);
const sealed = Buffer.concat([nonce, cipher.update(plainText), cipher.final(), cipher.getAuthTag()]);
```

### Python example

```python
import os
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

nonce = os.urandom(12)
sealed = nonce + AESGCM(key).encrypt(nonce, plain_text, None)
```

## Sources

- [OWASP Cryptographic Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html)

## Related rules

- [Encrypt the most sensitive fields](https://agentwranglers.se/playbook/data/personal-data/field-encryption) in Data
- [Store passwords with a slow hash](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts/password-storage) in Security testing
- [Make tokens from a secure random source](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts/secure-random-tokens) in Security testing
- [Keep the dependency tree small](https://agentwranglers.se/playbook/adversarial-testing/supply-chain-and-setup/small-dependency-tree) in Security testing

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets/standard-cryptography">Agent Wranglers security testing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Keep card numbers off your servers](https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets/hosted-payment-fields)
- [Data and secrets](https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets)
