Review AI-written cryptography against a fixed checklist: no deprecated algorithms, no hard-coded keys, a secure random source, adaptive password hashing, and no reused initialization vectors. Better still, ask whether the code should exist at all, since a maintained library call usually beats custom crypto from any author.
Why this code deserves extra care
Cryptographic code can run without errors and still be broken. A test that encrypts and decrypts proves little about whether the choice of mode, key handling or randomness is safe. OWASP lists Cryptographic Failures as its own category in the 2021 Top 10, and the page maps weaknesses such as use of a hard-coded key (CWE-321) and a hard-coded password (CWE-259) to it.
An assistant will often produce a plausible snippet in the style of older examples. You need a reviewer who knows what to look for.
The checklist
| Check | What OWASP guidance says |
|---|---|
| Algorithms | Avoid deprecated functions and padding schemes such as MD5, SHA1 and PKCS number 1 v1.5 |
| Keys | Generate keys cryptographically at random, manage and rotate them, and do not check them into source repositories |
| Passwords | Use strong, adaptive, salted hashing with a work factor, such as Argon2, scrypt, bcrypt or PBKDF2 |
| Randomness | Use a cryptographically secure random number generator for cryptographic purposes |
| IVs and nonces | Never reuse an initialization vector with the same fixed key |
| Mode | Prefer authenticated encryption over encryption alone |
| Transport | TLS with forward secrecy; do not send sensitive data over legacy protocols |
Review steps
- Search the diff for the names of hash, cipher and random functions. List each one with its purpose.
- Compare each against the table. Anything on the deprecated list needs a written reason.
- Trace where each key comes from and where it is stored. A literal string in code fails the review.
- Check password handling separately. A fast hash, even salted, is the wrong tool.
- Confirm that a standard library or maintained package does the work. Hand-rolled primitives are a red flag.
- Add a test that would fail if the algorithm were downgraded.
What a scanner can and cannot do
A static analysis rule can flag a weak hash call or a literal key. It will not tell you that a nonce is derived from a counter that resets after restart. That judgment is the reviewer's, which is why the checklist exists. For the matching key problem see hardcoded secrets in AI-generated code.
Where Safeguard fits
Safeguard runs SAST and secret detection on pull requests, and a policy can block a merge on those findings. A free scan will show what is already in your repository.
Try it yourself
Click through it at your own pace, or open it full screen.
Click through the code scan and look at how a finding points to the exact line and rule.
Quick check
Is SHA1 ever acceptable?
OWASP advises avoiding it among deprecated functions. If an old protocol forces it, document the reason and plan to move.
Should I let an assistant write encryption code at all?
Use it to wire up a vetted library, not to invent primitives, and review the result against this list.
Sources
Last reviewed: 19 October 2026.