← All articlesMobile applications

How to Remove an Embedded Key from an Android App and Verify Its Origin

Adding Android Keystore to a project is not enough to remove an embedded encryption key. You need to establish where the key used in a specific operation comes from, how it is created, and what happens on subsequent access or when an error occurs. We will explore this using a fictional app called Local Notes and our own synthetic records. The review will support a conclusion about one save scenario: embedded material has been replaced with a new key, and the observed operation actually uses that key through Keystore.

Define the Scenario and Trust Boundary

Start with one function: saving a local note. Prepare fictional text, such as ‘Test record A,’ and map the path from the button press to the encryption operation. Document which parts of the implementation are in scope. This scope lets you make a verifiable conclusion without automatically extending it to the app’s other data.

Android Keystore allows cryptographic operations with non-exportable key material. When such a key is used, its material does not enter the app process. This is an important boundary: the app can use the key without receiving its material. However, a compromised process may still be able to use the key, so Keystore must not be described as a guarantee against every consequence of compromise.

Trace the Key from Encryption Back to Its Creation

The checks below are original editorial guidance, not an official Android or OWASP procedure. In the selected save operation, trace the key passed to encryption back to its source: where the object comes from, which branch creates the key, and which retrieves an existing one. Record the APIs called, the provider, and the alias—the name of the selected entry—without exposing key material.

AndroidKeyStore is registered as a KeyStore type and as a provider for KeyGenerator and KeyPairGenerator. The documentation requires explicitly specifying the provider when working with Android Keystore. Do not automatically apply this rule to other cryptographic operations: explicitly selecting a provider there can cause compatibility problems. The presence of the AndroidKeyStore string or an alias alone does not establish the origin of the key actually used.

Rule Out Embedded Material, Including Import Paths

Review the reachable paths that construct the key for saving a note, along with related code, resources, and bundled files. Look for predefined bytes and strings, decoded constants, and material assembled from multiple parts. The goal is to connect findings to the specific operation, rather than merely compile a list of suspicious strings.

Keystore supports both generation and import. Moving previously embedded material into Keystore therefore does not confirm that it has been replaced with a new key. For this fix, the acceptance criteria are traced generation of a new key through AndroidKeyStore, use of that specific key, and no embedded material on the reviewed paths. Permitted uses are set during generation or import and cannot be changed afterward; account for this when creating a new entry.

Confirm Saving and Subsequent Key Retrieval

Run a positive control using your own synthetic record. Save it, read it, and compare its contents with the original. Then restart the app and read it again, tracing retrieval of the key from the selected Keystore entry. Match the observed encryption operation to the key whose origin you have already verified.

Success requires both behavior and provenance: the record matches the original, subsequent reading succeeds, and the key retrieval chain is confirmed. A ‘Saved’ message or successful reading alone is insufficient. Separately document how the change will be checked for previously saved data; a result obtained with a new test record does not confirm that case works.

Verify Failure Without Falling Back to an Embedded Key

In an isolated test build, make the selected key unavailable by substituting a test implementation of the access layer. Use only fictional records. Trace error handling: it must not switch the selected scenario to a predefined key or material assembled from constants.

Acceptance requires an observable operation failure and inspection of the error-handling branch taken. Verify that the app does not report a successful save when no save occurred. Keep these observations alongside the positive control: one failure does not prove the absence of all fallback paths, just as one successful run does not validate the entire implementation.

Check the Mode, IV, and Hardware Backing Separately

OWASP recommends authenticated modes, such as AES/GCM/NoPadding. For the selected scenario, check the configuration, how the IV is obtained, and the use of GCMParameterSpec for GCM decryption. The IV must be unique for every operation; predefined, all-zero, and reused IVs are unacceptable. Different IVs across several runs are an observation that must be supplemented by implementation review, not proof of uniqueness across all operations.

For apps targeting Android 10 or higher, check the hardware backing of the key actually used through KeyInfo.getSecurityLevel(). TRUSTED_ENVIRONMENT and STRONGBOX indicate secure hardware. This is a separate characteristic: it does not confirm that new material was generated instead of importing embedded material, and it does not eliminate the possibility of key use when the process is compromised.

Document Priorities and the Limits of the Result

First, replace the embedded material in the selected scenario and confirm the origin of the key used. During the same review, fix any mode or IV-handling issues found. Complete the positive and negative controls, and record hardware backing separately. For the product owner, the result should be a report documenting the review scope, observations, and acceptance criteria met.

Finding no issues in this scenario does not prove that the entire app is free of embedded keys. These checks also provide no statistical guarantee of security. If the product includes a website or web component, CheckMyApp offers a free website/web-product audit; the Android review described here remains a separate development task.

Sources and documentation

  1. MASWE-0007: Use of Hardcoded Cryptographic Keys
  2. Cryptography
  3. Android Keystore system
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free