{"record":{"id":"55cf2b0fb2f57751","repo":"MuntashirAkon/AppManager","slug":"no-keypair-with-alias-ecc-key-alias","errorCode":null,"errorMessage":"No KeyPair with alias ${ECC_KEY_ALIAS}","messagePattern":"No KeyPair with alias (.+?)","errorType":"exception","errorClass":"CryptoException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/crypto/ECCCrypto.java","lineNumber":59,"sourceCode":"        return super.getEncryptedAesKey();\n    }\n\n    @NonNull\n    static SecretKey generateAesKey() {\n        SecureRandom random = new SecureRandom();\n        byte[] key = new byte[AES_KEY_SIZE_BITS/8];\n        random.nextBytes(key);\n        return new SecretKeySpec(key, \"AES\");\n    }\n\n    @NonNull\n    static SecretKey decryptAesKey(@NonNull byte[] encryptedAesKey) throws CryptoException {\n        KeyPair keyPair;\n        try {\n            KeyStoreManager keyStoreManager = KeyStoreManager.getInstance();\n            keyPair = keyStoreManager.getKeyPair(ECC_KEY_ALIAS);\n            if (keyPair == null) {\n                throw new CryptoException(\"No KeyPair with alias \" + ECC_KEY_ALIAS);\n            }\n        } catch (Exception e) {\n            throw new CryptoException(e);\n        }\n        try {\n            Cipher cipher = Cipher.getInstance(ECC_CIPHER_TYPE, new BouncyCastleProvider());\n            cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivateKey());\n            return new SecretKeySpec(cipher.doFinal(encryptedAesKey), \"AES\");\n        } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | BadPaddingException\n                | IllegalBlockSizeException e) {\n            throw new CryptoException(e);\n        }\n    }\n\n    @NonNull\n    static byte[] encryptAesKey(@NonNull SecretKey key) throws CryptoException {\n        KeyPair keyPair;\n        try {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ECCCrypto.java#L41-L77","documentation":"ECCCrypto.decryptAesKey looks up the ECC key pair (alias ECC_KEY_ALIAS) via KeyStoreManager to unwrap the AES key. If no such KeyPair exists in the keystore, it throws CryptoException with the alias name, so decryption cannot proceed.","triggerScenarios":"Calling decryptAesKey (or decrypt through AESCrypto in ECC mode) when no KeyPair is stored under ECC_KEY_ALIAS, or KeyStoreManager.getKeyPair throws and is wrapped into CryptoException.","commonSituations":"Decrypting files on a device/installation where the ECC keys were never generated; app data cleared or device migration losing keystore keys; hardware keystore keys unrecoverable after OS update or backup restore to a new device.","solutions":["Generate the ECC key pair (generateKeyPair / KeyStoreManager for ECC_KEY_ALIAS) on this device before decrypting","Use the same device/app install that originally encrypted the data — keystore keys are non-exportable","If keys are unrecoverable, the data cannot be decrypted; restore from an alternative source"],"exampleFix":"// before\nSecretKey key = ECCCrypto.decryptAesKey(encryptedKey); // no keypair yet\n// after\nif (KeyStoreManager.getInstance().getKeyPair(ECC_KEY_ALIAS) == null) {\n    KeyStoreManager.getInstance().generateKeyPair(ECC_KEY_ALIAS); // or refuse to decrypt\n}\nSecretKey key = ECCCrypto.decryptAesKey(encryptedKey);","handlingStrategy":"try-catch","validationCode":"KeyPair kp = KeyStoreManager.getInstance().getKeyPair(ECC_KEY_ALIAS);\nif (kp == null) {\n    // generate or refuse to decrypt\n    throw new IllegalStateException(\"ECC key pair missing; data from this install cannot be decrypted\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    SecretKey key = ECCCrypto.decryptAesKey(encryptedKey);\n} catch (CryptoException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"No KeyPair\")) {\n        // inform user the keystore key is unavailable on this device\n    }\n}","preventionTips":["Generate ECC keys at app first-run, before any encryption","Never expect keystore keys to survive app data clear or device migration","Check key existence before offering decryption features"],"tags":["crypto","android","keystore","ecc","missing-key"],"backgroundTag":"resource-not-found","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}