Repository navigation
Accepting CryptoKey in node:crypto APIs #55293
Copy link
Copy link
Closed
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.deprecationsIssues and PRs related to deprecations.Issues and PRs related to deprecations.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.never-staleIssues and PRs exempt from automated stale handling.Issues and PRs exempt from automated stale handling.webcryptoIssues and PRs related to the Web Crypto API.Issues and PRs related to the Web Crypto API.
Description
Activity
cc @nodejs/crypto
My preferred state is to have a way to convert KeyObject <> CryptoKey both ways (KeyObject.from (while respecting extractable) and #55262) but not have
node:cryptoAPIs acceptCryptoKeyand not haveSubtleCryptoacceptKeyObject(already not possible).This is even with my
joseauthor/maintainer hat on. I don't make use ofCryptoKeyinnode:cryptoAPIs. I do make use ofKeyObject.from, but beforeKeyObject.fromconversion I do check theCryptoKeyproperties and the resultingKeyObjectis never returned to the user.Reacted by Fabian Meyer, Bruno Heridet and Nikita Skovoroda- addedcryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.webcryptoIssues and PRs related to the Web Crypto API.Issues and PRs related to the Web Crypto API.never-staleIssues and PRs exempt from automated stale handling.Issues and PRs exempt from automated stale handling.
on Oct 6, 2024 - added a commit that references this issue
on Mar 18, 2026 - addeddeprecationsIssues and PRs related to deprecations.Issues and PRs related to deprecations.
on Mar 18, 2026 - added a commit that references this issue
on Mar 20, 2026 - added a commit that references this issue
on Mar 25, 2026 - added a commit that references this issue
on Mar 28, 2026 - added 3 commits that reference this issue
on Mar 28, 2026 12 remaining items
- added a commit that references this issue
on Jun 15, 2026 - added a commit that references this issue
on Jun 17, 2026
Metadata
Metadata
Assignees
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.deprecationsIssues and PRs related to deprecations.Issues and PRs related to deprecations.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.never-staleIssues and PRs exempt from automated stale handling.Issues and PRs exempt from automated stale handling.webcryptoIssues and PRs related to the Web Crypto API.Issues and PRs related to the Web Crypto API.
The following APIs accept a
CryptoKeyinstance and process the operation despite the restrictions put forth on theCryptoKeyinstance (e.g. algorithm, usages, extractable)extractable)This list is according to the docs, but i suspect it's possible that hkdf and pbkdf2 allow this too.
This issue is to discuss a way forward to deal with this issues.
KeyObject.from
#37240 attempted to do something about KeyObject.from but i think the outcome would not solve the issues above.
I believe that converting key representations is not an issue so long as the more restrictive key representation's properties are upheld.
We can take a drastic stance and deprecate / in due time remove KeyObject.from entirely, or make KeyObject.from respect the
extractableproperty and duly document that once the key is converted the CryptoKey restrictions are not upheld anymore. I'd much rather see the latter.Another possible approach would be to disable KeyObject.export on keys that came from non-extractable CryptoKey.
APIs accepting CryptoKey but ignoring its parameters.
We could deprecate the use of CryptoKey in these APIs entirely or emulate WebCryptoAPI behaviour and check the CryptoKey usages and algorithm slots, either way this would be a doc-only deprecation at first, then --pending-deprecation, runtime deprecation, throw behaviour at the end.