Android cryptography checks
Common cryptography mistakes in Android apps
Cryptography findings are usually not broken algorithms. They are correct algorithms used with the wrong mode, a reused value or a key shipped inside the app.
Why these are common
Java and Android cryptography APIs accept short transformation strings and will choose defaults for anything left out. Code copied from old answers often uses those defaults, fixed values for convenience or a key stored as a constant. These checks belong to MASVS-CRYPTO.
Patterns to look for
| Pattern | Problem | Safer choice |
|---|---|---|
Cipher.getInstance("AES") or AES/ECB/... | The short form commonly resolves to ECB mode, which encrypts equal blocks to equal output and reveals patterns. | An authenticated mode such as AES/GCM/NoPadding. |
| Fixed or zero IV or nonce | With GCM, reusing a nonce under the same key breaks confidentiality and integrity. | A fresh random IV for every encryption, stored with the ciphertext. |
| Key as a string constant or resource | Anyone with the APK has the key; the encryption only obscures the data. | A key generated in the Android Keystore, or a server-held secret. |
| MD5 or SHA-1 for integrity or passwords | Broken for collision resistance; fast hashes are unsuitable for passwords. | SHA-256 or better for integrity; password hashing belongs on the server. |
java.util.Random for tokens or keys | Predictable output. | SecureRandom. |
The Android cryptography guidance lists recommended algorithms and deprecated providers.
Static review
- Search for
Cipher.getInstance,MessageDigest.getInstance,SecretKeySpec,IvParameterSpec,GCMParameterSpecandRandom, and record the transformation strings and where key and IV bytes come from. - Check native libraries and bundled SDKs as well as app code; the same mistakes appear there.
- Decide what each use protects. ECB on a value that is never sensitive is a code quality note; ECB on stored health data is a finding.
Confirming impact
Static review usually establishes the mistake itself. To show impact, connect it to data: for a hardcoded key, show that it decrypts a value the app actually stores or sends, using test data on an authorized device. For a predictable token, show where the token is used and whether the server accepts it.
Without that link, report the pattern as a candidate with its location and the data it appears to protect, and say what would be needed to confirm it.
Report it with the evidence
Include the code location, the exact transformation or API call, the source of the key and IV and the data protected. Recommend the specific replacement rather than "use strong crypto", and note when a key must be rotated because it has already shipped.
Hardcoded keys overlap with secrets in general; see how to triage a hardcoded API key. Use the report evidence guide to structure the finding.