{"record":{"id":"0e3ae9c7aa33cb83","repo":"MuntashirAkon/AppManager","slug":"the-alias-alias-does-not-have-a-keypair","errorCode":null,"errorMessage":"The alias ${alias} does not have a KeyPair.","messagePattern":"The alias (.+?) does not have a KeyPair\\.","errorType":"exception","errorClass":"KeyStoreException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreManager.java","lineNumber":356,"sourceCode":"    @Nullable\n    private Key getKey(String alias, @Nullable char[] password)\n            throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {\n        if (password == null) {\n            password = getAliasPassword(alias);\n        }\n        Key key = mAmKeyStore.getKey(alias, password);\n        Utils.clearChars(password);\n        return key;\n    }\n\n    @Nullable\n    public SecretKey getSecretKey(String alias)\n            throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {\n        Key key = getKey(alias);\n        if (key instanceof SecretKey) {\n            return (SecretKey) key;\n        }\n        throw new KeyStoreException(\"The alias \" + alias + \" does not have a KeyPair.\");\n    }\n\n    @Nullable\n    public KeyPair getKeyPair(String alias)\n            throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {\n        Key key = getKey(alias);\n        if (key instanceof PrivateKey) {\n            return new KeyPair((PrivateKey) key, getCertificate(alias));\n        }\n        throw new KeyStoreException(\"The alias \" + alias + \" does not have a KeyPair.\");\n    }\n\n    @Nullable\n    public KeyPair getKeyPairNoThrow(String alias) {\n        try {\n            return getKeyPair(alias);\n        } catch (Exception e) {\n            return null;","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreManager.java#L338-L374","documentation":"getSecretKey retrieves the key stored under an alias and requires it to be a SecretKey. If getKey returns a key of any other type (e.g. a PrivateKey), the alias does not hold a secret key, and a KeyStoreException with this message is thrown. Note the message text says 'KeyPair' but the actual expectation is a SecretKey.","triggerScenarios":"Calling getSecretKey(alias) for an alias that holds a private/certificate entry instead of a secret key, or an alias whose key was stored with the wrong entry type (misleading message).","commonSituations":"Using an alias reserved for signing key pairs with the AES crypto API; migration storing keys under wrong types; alias mix-ups between KeyPair and SecretKey namespaces.","solutions":["Use the correct alias that was stored via addSecretKey","Call getKeyPair(alias) instead if the alias holds a KeyPair","Check the stored entry type with getKey/containsAlias before choosing the accessor"],"exampleFix":"// before\nSecretKey key = ksManager.getSecretKey(\"my-signing-key\"); // wrong: alias holds a KeyPair\n// after\nKeyPair kp = ksManager.getKeyPair(\"my-signing-key\");\nSecretKey key = ksManager.getSecretKey(\"my-aes-key\");","handlingStrategy":"validation","validationCode":"Key key = ksManager.getKey(alias);\nif (!(key instanceof SecretKey)) {\n    throw new IllegalArgumentException(\"Alias does not hold a SecretKey\");\n}","typeGuard":"boolean isSecretKey(Key k) {\n    return k instanceof SecretKey;\n}","tryCatchPattern":"try {\n    SecretKey sk = ksManager.getSecretKey(alias);\n} catch (KeyStoreException e) {\n    // alias holds another key type; fall back to getKeyPair or regenerate\n}","preventionTips":["Keep separate alias namespaces for secret keys vs key pairs","Use getKey/instanceof to check entry type before accessor choice","Fix or rely on the (misleading) message text accordingly when reporting bugs"],"tags":["keystore","type-mismatch","crypto"],"backgroundTag":"type-mismatch","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}