Title: Crypto cant sign/verify prehashed inputs · Issue #60263 · nodejs/node · GitHub
Open Graph Title: Crypto cant sign/verify prehashed inputs · Issue #60263 · nodejs/node
X Title: Crypto cant sign/verify prehashed inputs · Issue #60263 · nodejs/node
Description: Version Node.js v22.20.0 - Node.js v24.10.0 Platform all Subsystem crypto What steps will reproduce the bug? const crypto = require('crypto'); const message = Buffer.from('LmM8PqCO1QIpTse0s+MQEJ7YXOSZuqyjPCJ4tIZ+OrU=', 'base64'), prehash...
Open Graph Description: Version Node.js v22.20.0 - Node.js v24.10.0 Platform all Subsystem crypto What steps will reproduce the bug? const crypto = require('crypto'); const message = Buffer.from('LmM8PqCO1QIpTse0s+MQEJ7YX...
X Description: Version Node.js v22.20.0 - Node.js v24.10.0 Platform all Subsystem crypto What steps will reproduce the bug? const crypto = require('crypto'); const message = Buffer.from('LmM8PqCO1QIpT...
Opengraph URL: https://github.com/nodejs/node/issues/60263
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crypto cant sign/verify prehashed inputs","articleBody":"### Version\n\nNode.js v22.20.0 - Node.js v24.10.0\n\n### Platform\n\n```text\nall\n```\n\n### Subsystem\n\ncrypto\n\n### What steps will reproduce the bug?\n```js\nconst crypto = require('crypto');\n\nconst message\t\t \t= Buffer.from('LmM8PqCO1QIpTse0s+MQEJ7YXOSZuqyjPCJ4tIZ+OrU=', 'base64'),\n\t\t\tprehash \t \t= crypto.createHash('sha256').update(message).digest();\n\nconst namedCurve \t= 'secp256k1',\n\t\t\tkeyPair \t \t= crypto.generateKeyPairSync('ec', { namedCurve }),\n\t\t\tsignature\t\t= crypto.sign(null, prehash, {\n\t\t\t\t\t\t\t\t\t\t\tkey\t\t\t\t\t: keyPair.privateKey,\n\t\t\t\t\t\t\t\t\t\t\tdsaEncoding\t: 'ieee-p1363'\n\t\t\t\t\t\t\t\t\t\t});\n\nconsole.log(crypto.verify(null, message, {\n\tkey\t\t\t\t\t: keyPair.publicKey,\n\tdsaEncoding\t: 'ieee-p1363'\n}, signature), ' message internal-internal (must be false)');\n\nconsole.log(crypto.verify(null, prehash, {\n\tkey\t\t\t\t\t: keyPair.publicKey,\n\tdsaEncoding\t: 'ieee-p1363'\n}, signature), ' prehash internal-internal (must be true)');\n\n// Simple unitary test:\nconst PUBLIC_KEY_PEM = '-----BEGIN PUBLIC KEY-----\\n' +\n\t\t\t\t\t\t\t\t\t\t \t'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE6Yvel06IICYJZ/XsuPEFTpDt0aU8dwLK\\n' +\n\t\t\t\t\t\t\t\t\t\t \t'jvgxyYTeZ/vlS49/PDRIr5JDz+QNWFB9ZM9tf4i9SdT0LVtlgRj3dQ==\\n' +\n\t\t\t\t\t\t\t\t\t\t \t'-----END PUBLIC KEY-----',\n\t\t\tpublicKey \t\t = crypto.createPublicKey(PUBLIC_KEY_PEM),\n\t\t\tsignOfPreHash = Buffer.from('Djv4wD3eWu8lHI3DrN2Dypdrirj+J1rfJD5O1B/Tw8sYy38jms77neECQ0S9LHpnWun+Jb9iOZNbYjH+CoVUnA==', 'base64');\n\nconsole.log('== BUG HERE ==');\n\nconsole.log(crypto.verify(null, message, {\n\tkey\t\t\t\t\t: publicKey,\n\tdsaEncoding\t: 'ieee-p1363'\n}, signOfPreHash), ' message external-internal (must be false)');\n\nconsole.log(crypto.verify(null, prehash, {\n\tkey\t\t\t\t\t: publicKey,\n\tdsaEncoding\t: 'ieee-p1363'\n}, signOfPreHash), ' prehash external-internal (must be true)');\n```\n### How often does it reproduce? Is there a required condition?\n\nNo precondition required.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nWhen send null to algorithm param i expect that message payload be raw, prehashed, dont want an additional internal rehash. This make impossible verify or sign keeping compatibility with external systems.\n\n### What do you see instead?\n\ncrypto module ignore my null and place a sha256 algorithm instead, performing a double hash internally.\n\n### Additional information\n\nMany external systems provide hash + signarure to verify, but we cannot do this because the implicit rehash of crypto module.","author":{"url":"https://github.com/codermapuche","@type":"Person","name":"codermapuche"},"datePublished":"2025-10-15T11:36:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/60263/node/issues/60263"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ce46869f-31ed-ca9c-e4b3-dbd56a73f57f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DAD2:299DE6:51115B:6EFB70:6A4D3E66 |
| html-safe-nonce | 5ec4698b8fb67082d0299f0f7cf3a8455d778da6dbf4826b203658514537572c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQUQyOjI5OURFNjo1MTExNUI6NkVGQjcwOjZBNEQzRTY2IiwidmlzaXRvcl9pZCI6IjgwMjIwMzc0OTk0NjIxMDY3MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 335dc3376981bf61583d24c1e7a3a590ad952f7d99cda523dd21ad027b4ce49f |
| hovercard-subject-tag | issue:3517620790 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/60263/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fe31d3a7309286c72209d659174e0fe5a24c0fd21f8af80705b969dc89de8f85/nodejs/node/issues/60263 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fe31d3a7309286c72209d659174e0fe5a24c0fd21f8af80705b969dc89de8f85/nodejs/node/issues/60263 |
| og:image:alt | Version Node.js v22.20.0 - Node.js v24.10.0 Platform all Subsystem crypto What steps will reproduce the bug? const crypto = require('crypto'); const message = Buffer.from('LmM8PqCO1QIpTse0s+MQEJ7YX... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | codermapuche |
| hostname | github.com |
| expected-hostname | github.com |
| None | 92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fc8347865a14e2ec811533d68f929cf4e0ec19 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width