diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index c0336927bdd99a..41698e5f02939e 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -308,12 +308,14 @@ function parseKeyFormatAndType(enc, keyType, isPublic, objName) { isInput ? kKeyFormatPEM : undefined, option('format', objName)); + const isRequired = (!isInput || + format === kKeyFormatDER) && + format !== kKeyFormatJWK; const type = parseKeyType(typeStr, - !isInput || format === kKeyFormatDER, + isRequired, keyType, isPublic, option('type', objName)); - return { format, type }; } diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index e048a82e451613..89ad0874e0ffb9 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -61,7 +61,10 @@ void GetKeyFormatAndTypeFromJs( config->type_ = Just(static_cast( args[*offset + 1].As()->Value())); } else { - CHECK(context == kKeyContextInput && config->format_ == kKeyFormatPEM); + CHECK( + (context == kKeyContextInput && config->format_ == kKeyFormatPEM) || + (context == kKeyContextGenerate && config->format_ == kKeyFormatJWK) + ); CHECK(args[*offset + 1]->IsNullOrUndefined()); config->type_ = Nothing(); }