apache/cassandra · error · GeneralSecurityException

Failed to decrypt the private key data. Either the password…

Error message

Failed to decrypt the private key data. Either the password provided for the key is wrong or the private key data is corrupted. msg=

What it means

Thrown by PEMReader.extractPrivateKey when PKCS8 EncryptedPrivateKeyInfo decryption fails while parsing a PEM private key. This is a generic guard: the supplied keyPassword did not decrypt the key, or the DER-encoded key bytes are corrupt/truncated. It wraps the underlying GeneralSecurityException (typically BadPaddingException from the PBE cipher).

Solutions

  1. Verify the key_password configured for the SSL factory matches the passphrase the key was encrypted with
  2. Re-export the PEM key and confirm it is valid PKCS#8 (e.g. with openssl pkey -in key.pem -text)
  3. If the key is unencrypted, ensure the PEM block type matches what the parser expects (BEGIN PRIVATE KEY vs BEGIN ENCRYPTED PRIVATE KEY)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/java/org/apache/cassandra/security/PEMReader.java:129 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/0b8acfd04972ff25. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/security/PEMReader.java:129

            EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(derKeyBytes);
            logger.debug("Encrypted private key info's algorithm name: {}", epki.getAlgName());

            AlgorithmParameters params = epki.getAlgParameters();
            PBEKeySpec pbeKeySpec = new PBEKeySpec(keyPassword.toCharArray());
            Key encryptionKey = SecretKeyFactory.getInstance(epki.getAlgName()).generateSecret(pbeKeySpec);
            pbeKeySpec.clearPassword();
            logger.debug("Key algorithm: {}, key format: {}", encryptionKey.getAlgorithm(), encryptionKey.getFormat());

            Cipher cipher = Cipher.getInstance(epki.getAlgName());
            cipher.init(Cipher.DECRYPT_MODE, encryptionKey, params);
            byte[] rawKeyBytes;
            try
            {
                rawKeyBytes = cipher.doFinal(epki.getEncryptedData());
            }
            catch (BadPaddingException e)
            {
                throw new GeneralSecurityException("Failed to decrypt the private key data. Either the password " +
                                                   "provided for the key is wrong or the private key data is " +
                                                   "corrupted. msg=" + e.getMessage(), e);
            }
            logger.debug("Decrypted private key's length: {}", rawKeyBytes.length);

            keySpec = new PKCS8EncodedKeySpec(rawKeyBytes);
        }
        else
        {
            logger.debug("Key length: {}", derKeyBytes.length);
            keySpec = new PKCS8EncodedKeySpec(derKeyBytes);
        }

        PrivateKey privateKey = null;

        /*
         * Ideally we can inspect the OID (Object Identifier) from the private key with ASN.1 parser and identify the
         * actual algorithm of the private key. For doing that, we have to use some special library like BouncyCastle.

View on GitHub (pinned to 88fd0f6a0e)