{"record":{"id":"8a2f8e220933c6bb","repo":"MuntashirAkon/AppManager","slug":"couldn-t-find-any-suitable-algorithm","errorCode":null,"errorMessage":"Couldn't find any suitable algorithm","messagePattern":"Couldn't find any suitable algorithm","errorType":"exception","errorClass":"NoSuchAlgorithmException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreUtils.java","lineNumber":283,"sourceCode":"                BigInteger crtCoefficient = rsaIntegers.get(8);\n                //spec = new RSAPrivateKeySpec(modulus, privateExponent);\n                spec = new RSAPrivateCrtKeySpec(modulus, publicExponent, privateExponent,\n                        primeP, primeQ, primeExponentP, primeExponentQ, crtCoefficient);\n            } else if (dsaFormat) {\n                kf = KeyFactory.getInstance(\"DSA\");\n                List<BigInteger> dsaIntegers = new ArrayList<>();\n                ASN1Parse(bytes, dsaIntegers);\n                if (dsaIntegers.size() < 5) {\n                    throw new InvalidKeyException(\"Stream does not appear to be a properly formatted DSA key\");\n                }\n                BigInteger privateExponent = dsaIntegers.get(1);\n                BigInteger publicExponent = dsaIntegers.get(2);\n                BigInteger P = dsaIntegers.get(3);\n                BigInteger Q = dsaIntegers.get(4);\n                BigInteger G = dsaIntegers.get(5);\n                spec = new DSAPrivateKeySpec(privateExponent, P, Q, G);\n            } else {\n                throw new NoSuchAlgorithmException(\"Couldn't find any suitable algorithm\");\n            }\n            return kf.generatePrivate(spec);\n        }\n    }\n\n    public static byte[] getPemCertificate(@NonNull Certificate certificate)\n            throws CertificateEncodingException, IOException {\n        BASE64Encoder encoder = new BASE64Encoder();\n        try (ByteArrayOutputStream os = new ByteArrayOutputStream(X509Factory.BEGIN_CERT.length() +\n                X509Factory.BEGIN_CERT.length() + certificate.getEncoded().length + 2)) {\n            os.write(X509Factory.BEGIN_CERT.getBytes(StandardCharsets.UTF_8));\n            os.write('\\n');\n            encoder.encode(certificate.getEncoded(), os);\n            os.write('\\n');\n            os.write(X509Factory.END_CERT.getBytes(StandardCharsets.UTF_8));\n            return os.toByteArray();\n        }\n    }","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/crypto/ks/KeyStoreUtils.java#L265-L301","documentation":"generatePrivateKey falls through to its final else branch when the input matched none of the supported key formats (PKCS#8, RSA PKCS#1, DSA), throwing NoSuchAlgorithmException \"Couldn't find any suitable algorithm\". The library only supports these private key formats, and the stream matched none.","triggerScenarios":"Calling generatePrivateKey with a private key in an unsupported format: OpenSSH new format, EC keys (BEGIN EC PRIVATE KEY), PKCS#12 containers, PuTTY PPK, XML/Java JKS-exported keys, or unrecognizable headers.","commonSituations":"Users exporting modern EC or OpenSSH-format keys (ssh-keygen default since OpenSSH 7.8) instead of PEM RSA/DSA keys; submitting a keystore container (JKS/PKCS#12) instead of a bare key file.","solutions":["Convert the key to PKCS#8 PEM: openssl pkcs8 -topk8 -nocrypt -in key -out key_pkcs8.pem.","Convert OpenSSH-format keys: ssh-keygen -p -m PEM -f id_rsa (use an RSA key, not ed25519/EC).","Generate an RSA key if using EC/ed25519, since EC keys aren't supported by this parser.","Extract the private key from containers (e.g. openssl pkcs12 -in cert.p12 -nodes -nocerts) before passing it."],"exampleFix":"// before\nPrivateKey pk = KeyStoreUtils.generatePrivateKey(cr.openInputStream(ed25519KeyUri)); // unsupported\n// after\n// generate a supported key: ssh-keygen -t rsa -b 4096 -m PEM -f id_rsa\nPrivateKey pk = KeyStoreUtils.generatePrivateKey(cr.openInputStream(rsaPemKeyUri));","handlingStrategy":"validation","validationCode":"// only feed supported PEM formats (PKCS#8 / RSA / DSA private keys)\nString pem = readAll(is);\nboolean supported = pem.contains(\"-----BEGIN PRIVATE KEY-----\")\n        || pem.contains(\"-----BEGIN RSA PRIVATE KEY-----\")\n        || pem.contains(\"-----BEGIN DSA PRIVATE KEY-----\");\nif (!supported) {\n    throw new IllegalArgumentException(\"Unsupported key format — convert to PKCS#8 PEM first\");\n}","typeGuard":"boolean isSupportedPemFormat(InputStream is) throws IOException {\n    String s = readAll(is);\n    return s.contains(\"-----BEGIN PRIVATE KEY-----\")\n        || s.contains(\"-----BEGIN RSA PRIVATE KEY-----\")\n        || s.contains(\"-----BEGIN DSA PRIVATE KEY-----\");\n}","tryCatchPattern":"// try\ntry {\n    PrivateKey pk = KeyStoreUtils.generatePrivateKey(keyIs);\n} catch (NoSuchAlgorithmException e) {\n    if (e.getMessage().contains(\"Couldn't find any suitable algorithm\")) {\n        // unsupported format (EC/OpenSSH/PPK): convert to RSA PKCS#8 PEM and retry\n        retryWith(convertToPkcs8RsaPem(keyFile));\n    }\n}","preventionTips":["Standardize on unencrypted PKCS#8 RSA PEM (`openssl pkcs8 -topk8 -nocrypt`) for all imports.","Avoid ed25519/EC keys — this parser supports only RSA and DSA.","Convert OpenSSH new-format keys with `ssh-keygen -p -m PEM`.","Extract bare keys from JKS/PKCS#12 containers before calling generatePrivateKey."],"tags":["keystore","algorithm","unsupported-format","private-key"],"backgroundTag":"unsupported-operation","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"}