apache/cassandra · critical · IOException

cannot load cipher

Error message

cannot load cipher

What it means

buildCipher obtains a JCE Cipher for the configured transformation (e.g. AES/CBC/PKCS5Padding) with a key from the key provider. Failures like unknown algorithm, bad padding, invalid key, or invalid algorithm parameters are logged and rethrown as IOException("cannot load cipher").

Solutions

  1. Verify transparent_data_encryption_options.cipher is a valid JCE transformation supported by your JVM (typically AES/CBC/PKCS5Padding).
  2. Confirm the key_alias exists in the keystore: `keytool -list -v -keystore <file>`.
  3. Check the logged 'could not build cipher' stack trace for the specific JCE exception and fix key/IV material accordingly.
  4. Ensure the JVM has the needed crypto provider / unlimited strength policy.

Example fix

// before
transparent_data_encryption_options:
  cipher: AES/CBC/PKCS Padding
// after
transparent_data_encryption_options:
  cipher: AES/CBC/PKCS5Padding
Defensive patterns

Strategy: validation

Validate before calling

String transformation = tdeOptions.cipher; // e.g. AES/CBC/PKCS5Padding
Cipher.getInstance(transformation); // throws NoSuchAlgorithmException/NoSuchPaddingException if unsupported
KeyStore ks = KeyStore.getInstance("JCEKS");
try (InputStream in = new FileInputStream(keystorePath)) { ks.load(in, password.toCharArray()); }
if (!ks.containsAlias(tdeOptions.key_alias)) throw new IllegalStateException("Missing key alias: " + tdeOptions.key_alias);

Try / catch

try {
    Cipher c = cipherFactory.getEncryptor(tdeOptions.cipher, tdeOptions.key_alias);
} catch (IOException e) {
    logger.error("Cipher load failed; check cipher name and key_alias", e);
}

Prevention

When it happens

Trigger: getEncryptor/getDecryptor -> buildCipher with a cipher name the JVM's JCE provider doesn't support, a key_alias with no key in the provider, or IV bytes invalid for the algorithm.

Common situations: Typo'd cipher name in transparent_data_encryption_options (e.g. AES/CBC/PKCS5Padding misspelled), wrong key_alias, key deleted/rotated out of the keystore, or an older JDK lacking the algorithm.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/security/CipherFactory.java:137

            if (cachedCipher != null)
            {
                Cipher cipher = cachedCipher.cipher;
                // rigorous checks to make sure we've absolutely got the correct instance (with correct alg/key/iv/...)
                if (cachedCipher.mode == cipherMode && cipher.getAlgorithm().equals(transformation)
                    && cachedCipher.keyAlias.equals(keyAlias) && Arrays.equals(cipher.getIV(), iv))
                    return cipher;
            }

            Key key = retrieveKey(keyAlias);
            Cipher cipher = Cipher.getInstance(transformation);
            cipher.init(cipherMode, key, new IvParameterSpec(iv));
            cipherThreadLocal.set(new CachedCipher(cipherMode, keyAlias, cipher));
            return cipher;
        }
        catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e)
        {
            logger.error("could not build cipher", e);
            throw new IOException("cannot load cipher", e);
        }
    }

    private Key retrieveKey(String keyAlias) throws IOException
    {
        try
        {
            return cache.get(keyAlias);
        }
        catch (CompletionException e)
        {
            if (e.getCause() instanceof IOException)
                throw (IOException)e.getCause();
            throw new IOException("failed to load key from cache: " + keyAlias, e);
        }
    }

    /**

View on GitHub (pinned to 88fd0f6a0e)