Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support webcrypto hash algorithm arguments in node.js crypto hash apis #56464

Open
jasnell opened this issue Jan 4, 2025 · 1 comment
Open
Labels
crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. webcrypto

Comments

@jasnell
Copy link
Member

jasnell commented Jan 4, 2025

What is the problem this feature will solve?

In Node.js, we would do crypto.createHash('sha256') ... in web crypto we can do either crypto.subtle.digest('sha256', ...) or crypto.subtle.digest({ name: 'sha256' }, ...) (string or object). For consistency, it would be helpful to be able to support the webcrypto style arguments in the Node.js APIs also..

What is the feature you are proposing to solve the problem?

const { createHash } = require('node:crypto');

const algorithm = { name: 'sha256' };

// Support the same argument types in createHash/createHmac that are supported in web crypto..

const hash = createHash(algorithm);
// ...

What alternatives have you considered?

No response

@jasnell jasnell added the feature request Issues that request new features to be added to Node.js. label Jan 4, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Jan 4, 2025
@jasnell jasnell moved this from Awaiting Triage to Triaged in Node.js feature requests Jan 4, 2025
@jasnell jasnell added crypto Issues and PRs related to the crypto subsystem. webcrypto labels Jan 4, 2025
@panva
Copy link
Member

panva commented Jan 4, 2025

This would require to run the normalize algorithm12 name routine in a lot of places if meant to be done consistently across all APIs - this would appear in publicEncrypt, privateDecrypt, digest, hmac, sign, verify, all kdfs, and all other functions that do not even have a webcrypto counterpart but work with digest names.

I don't think we should cater to making node:crypto and SubtleCrypto more like one another, I don't see the payoff for the risk involved.

Footnotes

  1. https://github.com/nodejs/node/blob/804d41f9c73c03e670d8e788d14a2237c8c2a057/lib/internal/crypto/util.js#L320-L396

  2. https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. webcrypto
Projects
Development

No branches or pull requests

2 participants