Auditing application cryptographic API use and key handling
Cryptography needs an explicit security purpose, appropriate mechanisms and a safe lifecycle for keys and protected data. Understanding application cryptographic API use and key handling helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Cryptographic protection depends on the whole operation: the algorithm, its parameters, key handling and the way results are verified. Different mechanisms provide confidentiality, integrity or evidence of origin. Substituting one property for another can leave the important business requirement unprotected.
This section defines the requirements for the selection, implementation, and ongoing management of core cryptographic algorithms for an application. The objective is to ensure that only robust, industry-accepted cryptographic primitives are deployed, in alignment with current standards (e.g., NIST, ISO/IEC) and best practices. Organisations must ensure that each cryptographic component is selected based on peer-reviewed evidence and practical security testing.
Why it matters
Consider a realistic failure: an application uses an encryption or verification API correctly in isolation but trusts the wrong key, content or operation.
A weakness can undermine trust in stored records or messages even when their appearance does not change. Assessment should connect the defect to the data or action it protects and the capabilities available to an attacker.
A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.
How penetration testers check for it
Review the specific control expectations below against the code, deployment and observable application behaviour.
- Confirm that industry-validated implementations (including libraries and hardware-accelerated implementations) are used for cryptographic operations.
- Confirm that the application is designed with crypto agility such that random number, authenticated encryption, MAC, or hashing algorithms, key lengths, rounds, ciphers and modes can be reconfigured, upgraded, or swapped at any time, to protect against cryptographic breaks. Similarly, it must also be possible to replace keys and passwords and re-encrypt data. This will allow for seamless upgrades to post-quantum cryptography (PQC), once high-assurance implementations of approved PQC schemes or standards are widely available.
- Confirm that all cryptographic primitives utilize a minimum of 128-bits of security based on the algorithm, key size, and configuration. For example, a 256-bit ECC key provides roughly 128 bits of security where RSA requires a 3072-bit key to achieve 128 bits of security.
- Confirm that all cryptographic operations are constant-time, with no 'short-circuit' operations in comparisons, calculations, or returns, to avoid leaking information.
- Confirm that all cryptographic modules fail securely, and errors are handled in a way that does not enable vulnerabilities, such as Padding Oracle attacks.
- Trace key generation, access, replacement and verification.
- Test invalid inputs and failure handling with controlled data.
How to fix it
Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.
- Use maintained standard implementations and appropriate parameters.
- Protect keys throughout generation, use and retirement.
- Authenticate the content and identity that the operation actually relies on.
- Reject failed verification before trusting or processing the result.
An unusual cryptographic implementation is not enough to establish practical compromise. The report should explain the failed property and a defensible consequence.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Reviewing cryptographic handling of data during processing
- Reviewing cryptographic authenticators and challenge handling
- Implementing cryptographic key storage, rotation and revocation
Read about our methodology or contact pentested.com to discuss the security of your application code.