elastic/elasticsearch · error · GeneralSecurityException

Private Key encrypted with unsupported algorithm [{}]

Error message

Private Key encrypted with unsupported algorithm [{}]

What it means

Thrown by getCipherFromParameters when the DEK-Info algorithm token does not match any of the supported ciphers: DES-CBC, DES-EDE3-CBC, AES-128-CBC, AES-192-CBC, AES-256-CBC. Any other algorithm name (e.g. 'BF-CBC' for Blowfish, 'RC2-CBC', 'CAMELLIA-256-CBC', or a misspelled AES variant) is rejected as a GeneralSecurityException.

Source

Thrown at libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemUtils.java:532

            throw new IOException("Malformed PEM file, DEK-Info IV is invalid", e);
        }
        if ("DES-CBC".equals(algorithm)) {
            byte[] key = generateOpenSslKey(password, iv, 8);
            encryptionKey = new SecretKeySpec(key, DEPRECATED_DES_ALGORITHM);
        } else if ("DES-EDE3-CBC".equals(algorithm)) {
            byte[] key = generateOpenSslKey(password, iv, 24);
            encryptionKey = new SecretKeySpec(key, DEPRECATED_DES_EDE_ALGORITHM);
        } else if ("AES-128-CBC".equals(algorithm)) {
            byte[] key = generateOpenSslKey(password, iv, 16);
            encryptionKey = new SecretKeySpec(key, "AES");
        } else if ("AES-192-CBC".equals(algorithm)) {
            byte[] key = generateOpenSslKey(password, iv, 24);
            encryptionKey = new SecretKeySpec(key, "AES");
        } else if ("AES-256-CBC".equals(algorithm)) {
            byte[] key = generateOpenSslKey(password, iv, 32);
            encryptionKey = new SecretKeySpec(key, "AES");
        } else {
            throw new GeneralSecurityException("Private Key encrypted with unsupported algorithm [" + algorithm + "]");
        }
        String transformation = encryptionKey.getAlgorithm() + "/" + "CBC" + "/" + padding;
        Cipher cipher = Cipher.getInstance(transformation);
        cipher.init(Cipher.DECRYPT_MODE, encryptionKey, new IvParameterSpec(iv));
        return cipher;
    }

    /**
     * Performs key stretching in the same manner that OpenSSL does. This is basically a KDF
     * that uses n rounds of salted MD5 (as many times as needed to get the necessary number of key bytes)
     * <p>
     * https://www.openssl.org/docs/man1.1.0/crypto/PEM_write_bio_PrivateKey_traditional.html
     */
    private static byte[] generateOpenSslKey(char[] password, byte[] salt, int keyLength) {
        byte[] passwordBytes = CharArrays.toUtf8Bytes(password);
        MessageDigest md5 = SslUtil.messageDigest("md5");
        byte[] key = new byte[keyLength];
        int copied = 0;

View on GitHub (pinned to db6a809a66)

Solutions

  1. Re-encrypt the key with a supported cipher: 'openssl rsa -aes256 -in plain.key -out enc.key' (RSA) or 'openssl ec -aes256 -in plain.key -out enc.key' (EC).
  2. Confirm the DEK-Info algorithm token is exactly one of: DES-CBC, DES-EDE3-CBC, AES-128-CBC, AES-192-CBC, AES-256-CBC.
  3. If you cannot re-encrypt, decrypt the key with a tool that supports the original cipher and re-encrypt with OpenSSL using AES-256-CBC.

Example fix

// before: encrypt with Blowfish (unsupported)
//   openssl rsa -bf -in plain.key -out enc.key
// after: encrypt with AES-256-CBC (supported)
openssl rsa -aes256 -in plain.key -out enc.key
Defensive patterns

Strategy: validation

Validate before calling

// Validate the DEK-Info cipher is one of the supported algorithms
Set<String> SUPPORTED = Set.of("DES-CBC", "DES-EDE3-CBC", "AES-128-CBC", "AES-192-CBC", "AES-256-CBC");
String algo = /* algorithm token from DEK-Info */;
if (!SUPPORTED.contains(algo)) {
    throw new IllegalArgumentException("Unsupported PEM cipher: " + algo + "; re-encrypt with AES-256-CBC");
}

Try / catch

try { PemUtils.readPrivateKey(path, passwordSupplier); }
catch (GeneralSecurityException e) { if (e.getMessage().contains("unsupported algorithm")) { /* re-encrypt with AES */ } else throw e; }

Prevention

When it happens

Trigger: Loading an OpenSSL-format encrypted key produced by 'openssl rsa -<cipher>' or 'openssl ec -<cipher>' with an unsupported cipher such as '-bf' (Blowfish), '-camellia-*', or '-rc2'; a key produced by an older OpenSSL defaulting to an unsupported algorithm; a hand-edited DEK-Info header with a misspelled algorithm.

Common situations: Operators using legacy OpenSSL invocations; keys produced by non-conformant tooling; migration from environments that allowed Blowfish/Camellia; misspelled algorithm names from manual editing.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/75a911053507a866. Report an issue: GitHub.