Pick the fix
How should the server store API keys?
Hint 1 of 1
Can a random 256-bit key be guessed?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A SHA-256 hash of each random key, plus a short display prefix
Correct. A database leak doesn't expose working keys.
API keys are long and random, so a fast hash is enough: there is no small dictionary to brute-force. The server hashes the presented key and looks it up, and a leaked table holds no usable keys.
Why not the others?
- B Plain text, so support can read them. Anyone with database access can use them.
- C bcrypt with cost 14. Unnecessary for random keys and too slow per request.
- D Encrypted with a key stored next to them. Same as plain text if the database leaks.