---
title: "Use only standard cryptography · Agent Wranglers"
url: https://agentwranglers.se/playbook/application-security/cryptography-and-keys/standard-cryptography
id: APS-56
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1105
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 [Cryptography and keys](https://agentwranglers.se/playbook/application-security/cryptography-and-keys.md).

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

- ID: APS-56
- Level: Recommended
- Chapter: [Cryptography and keys](https://agentwranglers.se/playbook/application-security/cryptography-and-keys.md)
- 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.
- 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.
- 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/application-security/cryptography-and-keys/field-encryption.md). Passwords take [a slow hash](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/password-storage.md), and tokens take [a secure random source](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/secure-random-tokens.md).

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

- APS-58 [Encrypt the most sensitive fields](https://agentwranglers.se/playbook/application-security/cryptography-and-keys/field-encryption.md) in Application security
- APS-11 [Store passwords with a slow hash](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/password-storage.md) in Application security
- APS-14 [Make tokens from a secure random source](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/secure-random-tokens.md) in Application security
- APS-59 [Prepare your encryption for quantum computers](https://agentwranglers.se/playbook/application-security/cryptography-and-keys/post-quantum-readiness.md) in Application security
- APS-71 [Keep the dependency tree small](https://agentwranglers.se/playbook/application-security/supply-chain/small-dependency-tree.md) in Application security

**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/application-security/cryptography-and-keys/standard-cryptography">Agent Wranglers application security playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Renew certificates automatically](https://agentwranglers.se/playbook/application-security/cryptography-and-keys/certificate-renewal.md)
- Next: [Keep encryption keys in a key service](https://agentwranglers.se/playbook/application-security/cryptography-and-keys/key-management.md)
- [Cryptography and keys](https://agentwranglers.se/playbook/application-security/cryptography-and-keys.md)
