Mobile application security

Protecting mobile keys with platform keystores

Mobile keys with platform keystores: phone, key, chip arranged to illustrate protecting mobile keys with platform keystores.

A keystore can protect key operations without exposing the underlying key to application code. Understanding mobile keys with platform keystores helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Storage security concerns the copies that remain after an operation has finished. Files, databases, caches and exports can have different access rules and retention periods. A protected main database does not automatically protect a temporary copy or a restored backup.

You may find the keys being directly passed as arguments to cryptographic functions (byte arrays or string literals) or stored in variables or constants within the code. Typical representations of hardcoded keys include:

Cryptographic keys may be embedded files such as configuration files or key files, certificate files, or other resource files bundled with the app, making them accessible to anyone who can extract the app's resources. Real-world cases include storing API keys, SSL/TLS private keys, or encryption keys within these files, which can lead to serious security vulnerabilities if the app is reverse-engineered.

Why it matters

Consider a realistic failure: a copied app database remains readable because its encryption key sits beside it.

Exposure can involve private records, reusable credentials or information that identifies a customer. The practical impact depends on which copy is accessible, the access an attacker needs and whether the recovered material remains useful.

Mobile behaviour can change between a fresh installation, an authenticated session, background activity and a device migration. The assessment needs the actual release and representative supported device states.

How penetration testers check for it

Check key location, exportability, access conditions and behaviour on a locked device.

  • CommonCrypto: The CCCrypt can be initialized with raw key data in its key parameter.
  • CryptoKit: Although CryptoKit provides higher-level abstractions for cryptographic operations, developers might still hardcode cryptographic keys in different formats and feed it to methods like P256.Signing.PrivateKey.init(rawRepresentation:) or similar.
  • Raw Byte Arrays: Cryptographic keys may be directly embedded in the code as arrays of UInt8 or Data objects. For example, a 256-bit AES key might be represented as a [UInt8] array.
  • Base64-Encoded Strings: Developers might encode cryptographic keys as Base64 strings within the code, which can be easily decoded by attackers if discovered.
  • Check temporary copies, exports, backups and deletion behaviour.
  • Establish whether recovered information grants any further access.

How to fix it

Use the platform key service and avoid storing a recoverable plaintext key with encrypted data.

  • Retain only the information needed for the service.
  • Separate private working data from deliberately shared content.
  • Protect encryption keys independently of encrypted files.
  • Verify removal and recovery behaviour against the intended lifecycle.

Encryption is one part of the design. It cannot compensate for an application that willingly returns plaintext to an unauthorised caller.

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.

Read about our methodology or contact pentested.com to discuss your mobile applications.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo