You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To decrypt, you need to use createDecipheriv() instead of createCipheriv(). You then need to call decipher.setAuthTag() with the correct authentication tag, which you can obtain from the the original cipher after encryption as cipher.getAuthTag().
it does absolutely the same if i use createDecipheriv().
So decryption works without AuthTag and the issue is relevant.
i have changed the code for your convenience.
If there is a difference in behavior across versions of Node.js, it is likely due to differences in behavior across versions of OpenSSL. Since much of the node:crypto module is a thin wrapper around OpenSSL, we generally don't provide stronger security guarantees than OpenSSL. In other words, if this issue exists in a supported version of Node.js, it will be necessary to demonstrate that the issue does not also exist in OpenSSL.
If you are right and this is a security issue, then this was reported in violation of our security policies.
Here's what happens in Node.js 22.3.0 on Linux 6.1.92-1-MANJARO:
$ cat package.json { "dependencies": { "typescript": "^5.5.3" }}
$ node -vv22.3.0
$ node -p process.versions.openssl3.3.1
$ node main.mjs encrypted ---- njvgROnsKdsGnode:internal/crypto/cipher:184 const ret = this[kHandle].final(); ^Error: Unsupported state or unable to authenticate data at Decipheriv.final (node:internal/crypto/cipher:184:29) at decrypt (file:///home/tniessen/testgcm/main.mjs:22:70) at file:///home/tniessen/testgcm/main.mjs:26:19 at ModuleJob.run (node:internal/modules/esm/module_job:262:25) at async ModuleLoader.import (node:internal/modules/esm/loader:474:24) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)Node.js v22.3.0
Here's what happens in Node.js 22.1.0 on Windows 10:
encrypted ---- njvgROnsKdsGnode:internal/crypto/cipher:184 const ret = this[kHandle].final(); ^Error: Unsupported state or unable to authenticate data at Decipheriv.final (node:internal/crypto/cipher:184:29) at decrypt (file:///C:/Users/Tobias/main.mjs:22:70) at file:///C:/Users/Tobias/main.mjs:26:19 at ModuleJob.run (node:internal/modules/esm/module_job:262:25) at async ModuleLoader.import (node:internal/modules/esm/loader:474:24) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:119:5)Node.js v22.1.0
Here's what happens in Node.js 20.15.0 on Linux 6.5.0-1022-azure:
$ node main.mjs encrypted ---- njvgROnsKdsGnode:internal/crypto/cipher:193 const ret = this[kHandle].final(); ^Error: Unsupported state or unable to authenticate data at Decipheriv.final (node:internal/crypto/cipher:193:29) at decrypt (file:///home/tniessen/dev/dblp/main.mjs:22:70) at file:///home/tniessen/dev/dblp/main.mjs:26:19 at ModuleJob.run (node:internal/modules/esm/module_job:222:25) at async ModuleLoader.import (node:internal/modules/esm/loader:316:24) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)Node.js v20.15.0
Could you please test the code I provided above to avoid any dependency on third-party tools, such as typescript?
don't see the reason to test your code, coz i've reported the bug with my own.
thanks for your help.
Also, please note that @tniessen's code is nearly identical to yours——so any discrepancies between your execution and his will help to debug and address the issue (as @tniessen said).
This information is crucial in the process of this issue, and without it, there's not much that be done to help.
Hey @egorbeliy, I see you closed the issue. If you've resolved the issue, could you let us know how, so that anyone with this problem in the future can have an easier time resolving?
Hi @tniessen I am facing the same issue now after updating node.js from v18.2 to 22.x in AWS Lambda. Could you able to identify the root cause of why it is not working in some node.js versions
Error: Unsupported state or unable to authenticate data at Decipheriv.final (node:internal/crypto/cipher:184:29)
--
Just ran into the exact same issue here, except im using a more RECENT version of Nodejs (24.11.0), i get this exact same error and it does not hint at what actually went wrong cus it sure as f*** aint the auth tag, i have replicated this on c++ and checked it works and they have the exact same parameters as nodejs, nodejs is cooked.
@prithivirj@blul1ghtz Please provide us with minimal reproducible examples that demonstrate the issue you are facing, ideally including a self-contained code snippet as well as the expected behavior. Without more information, it is nearly impossible for us to determine what the issue is.
@tniessen haven't currently got the source code cus i gave up lol, but if i get it again ill send a pastebin if i get ffi-napi to work. it's just a simple script to decrypt using aes-256-gcm a known hex and iv using buffer.from
@tniessen hey i managed to get a version of ffi-napi to work on node 18.4.0 somehow, i haven't got source for the aes-256-gcm script yet as i am also experimenting with dpapi CryptProtectData in nodejs and ran into another issue which is ALSO well known, but there's nothing online about this happening with CryptProtectData, Should i create a new issue if this is unique to CryptProtectData (using ffi.Library) and nobody has had issues with that in particular or not?
More info here: https://pastebin.com/Q1AeC5uM
Activity
tniessen commentedon Jul 4, 2024
To decrypt, you need to use
createDecipheriv()instead ofcreateCipheriv(). You then need to calldecipher.setAuthTag()with the correct authentication tag, which you can obtain from the the originalcipherafter encryption ascipher.getAuthTag().egorbeliy commentedon Jul 4, 2024
it does absolutely the same if i use
createDecipheriv().So decryption works without AuthTag and the issue is relevant.
i have changed the code for your convenience.
egorbeliy commentedon Jul 4, 2024
@tniessen please test it out because it's critical security issue.
tniessen commentedon Jul 4, 2024
@egorbeliy In Node.js 22, I am seeing this error when running your code:
egorbeliy commentedon Jul 4, 2024
But for me it works well, is node version the same?
Feel free to check the video PoC https://drive.google.com/file/d/1HRQW7toSjHuPTrF4b6s5XoS1Kb1msSzM/view?usp=sharing
tniessen commentedon Jul 4, 2024
node:cryptomodule is a thin wrapper around OpenSSL, we generally don't provide stronger security guarantees than OpenSSL. In other words, if this issue exists in a supported version of Node.js, it will be necessary to demonstrate that the issue does not also exist in OpenSSL.egorbeliy commentedon Jul 5, 2024
so i got the same behaviour on v20 and v22.
Basically i got your point, you won't check it.
thanks.
tniessen commentedon Jul 5, 2024
@egorbeliy Alright, I'll give it another try. Here's the code I am using (
main.mjs):Here's what happens in Node.js 22.3.0 on Linux 6.1.92-1-MANJARO:
Here's what happens in Node.js 22.1.0 on Windows 10:
Here's what happens in Node.js 20.15.0 on Linux 6.5.0-1022-azure:
Could you please test the code I provided above to avoid any dependency on third-party tools, such as typescript?
egorbeliy commentedon Jul 5, 2024
don't see the reason to test your code, coz i've reported the bug with my own.
thanks for your help.
tniessen commentedon Jul 5, 2024
@egorbeliy I was trying to help. If you don't want to debug this issue together, there is not much I can do for you.
avivkeller commentedon Jul 7, 2024
Also, please note that @tniessen's code is nearly identical to yours——so any discrepancies between your execution and his will help to debug and address the issue (as @tniessen said).
This information is crucial in the process of this issue, and without it, there's not much that be done to help.
avivkeller commentedon Jul 7, 2024
Hey @egorbeliy, I see you closed the issue. If you've resolved the issue, could you let us know how, so that anyone with this problem in the future can have an easier time resolving?
egorbeliy commentedon Jul 7, 2024
hi @redyetidev.
We issue was using createCipheriv() to encrypt and decrypt.
Thanks a lot @tniessen.
prithivirj commentedon Jun 10, 2025
Hi @tniessen I am facing the same issue now after updating node.js from v18.2 to 22.x in AWS Lambda. Could you able to identify the root cause of why it is not working in some node.js versions
Error: Unsupported state or unable to authenticate data at Decipheriv.final (node:internal/crypto/cipher:184:29) --blul1ghtz commentedon Nov 2, 2025
Just ran into the exact same issue here, except im using a more RECENT version of Nodejs (24.11.0), i get this exact same error and it does not hint at what actually went wrong cus it sure as f*** aint the auth tag, i have replicated this on c++ and checked it works and they have the exact same parameters as nodejs, nodejs is cooked.
tniessen commentedon Nov 2, 2025
@prithivirj @blul1ghtz Please provide us with minimal reproducible examples that demonstrate the issue you are facing, ideally including a self-contained code snippet as well as the expected behavior. Without more information, it is nearly impossible for us to determine what the issue is.
blul1ghtz commentedon Nov 2, 2025
@tniessen haven't currently got the source code cus i gave up lol, but if i get it again ill send a pastebin if i get ffi-napi to work. it's just a simple script to decrypt using aes-256-gcm a known hex and iv using buffer.from
blul1ghtz commentedon Nov 2, 2025
@tniessen hey i managed to get a version of ffi-napi to work on node 18.4.0 somehow, i haven't got source for the aes-256-gcm script yet as i am also experimenting with dpapi CryptProtectData in nodejs and ran into another issue which is ALSO well known, but there's nothing online about this happening with CryptProtectData, Should i create a new issue if this is unique to CryptProtectData (using ffi.Library) and nobody has had issues with that in particular or not?
More info here: https://pastebin.com/Q1AeC5uM