From 276fe2be450a97ba686cf405befb60d4b9b2908e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 28 Jul 2026 15:00:41 +0200 Subject: [PATCH] crypto: clarify missing cipher error Explain that a cipher is required when a passphrase is provided. Signed-off-by: Filip Skokan PR-URL: https://github.com/nodejs/node/pull/64852 Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli --- lib/internal/crypto/keys.js | 4 +++- test/parallel/test-crypto-key-objects.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 250f99cfd20..4efc5a0d4e3 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -470,7 +470,9 @@ function parseKeyEncoding(enc, keyType, isPublic, objName) { encodingNames[type], 'does not support encryption'); } } else if (passphrase !== undefined) { - throw new ERR_INVALID_ARG_VALUE(option('cipher', objName), cipher); + throw new ERR_INVALID_ARG_VALUE( + option('cipher', objName), cipher, + 'is required when a passphrase is specified'); } } diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index 775b752ac3b..dadeb780cf6 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -1014,7 +1014,8 @@ if (!process.features.openssl_is_boringssl) { }, { name: 'TypeError', code: 'ERR_INVALID_ARG_VALUE', - message: "The property 'options.cipher' is invalid. Received undefined" + message: "The property 'options.cipher' is required when a " + + 'passphrase is specified. Received undefined', }); }