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

crypto: getDecoder throws "AssertionError: Cannot change encoding" when encoding is "ucs2", "ucs-2" or "utf-16le". #8236

Closed
atstoyanov opened this issue Aug 23, 2016 · 3 comments
Labels
crypto Issues and PRs related to the crypto subsystem.

Comments

@atstoyanov
Copy link
Contributor

atstoyanov commented Aug 23, 2016

  • v6.3.0:
  • Windows 64-bit:

I've got similar issue as:
#5655
when I'm using as output encoding 'ucs2', 'usc-2' or 'utf-16le'. If I'm using 'utf16le' the code works.

Here is the not working code:
var decrypted = decipher.update(value, 'base64', 'usc2');

Output:

Stack: AssertionError: Cannot change encoding at getDecoder (crypto.js:105:3) at Decipheriv.Cipher.update (crypto.js:146:21)

and here the working one:
var decrypted = decipher.update(value, 'base64', 'utf16le');

According to the documentation:

The output_encoding specifies the output format of the enciphered data, and can be 'latin1', 'ascii' or 'utf8'.

the utf16le is not supported as output encoding, but it works if you specify 'utf16le'.

The change in lib/crypto.js fix the issue with utf-8, but not with utf-16le.
There is a function 'normalizeEncoding' in lib/internal/util.js that can be used to normalize the encoding.

@addaleax addaleax added the crypto Issues and PRs related to the crypto subsystem. label Aug 23, 2016
@addaleax
Copy link
Member

There is a function 'normalizeEncoding' nn lib/internal/util.js that can be used to normalize the encoding.

Sounds like you can submit a pull request with that, if you like? There’s some info in https://github.com/nodejs/node/blob/master/CONTRIBUTING.md on how to do that.

@jasnell
Copy link
Member

jasnell commented Aug 26, 2016

@atstojanov ... are you interested in writing up a pull request for this?

@atstoyanov
Copy link
Contributor Author

@jasnell yes, I'm.

atstoyanov added a commit to atstoyanov/node that referenced this issue Sep 1, 2016
Normalize the encoding in getDecoder() before using it. Fixes an
AssertionError: "Cannot change encoding" when encoding is "ucs2",
"ucs-2" or "utf-16le"

Fixes: nodejs#8236
Fishrock123 pushed a commit that referenced this issue Sep 14, 2016
Normalize the encoding in getDecoder() before using it. Fixes an
AssertionError: "Cannot change encoding" when encoding is "ucs2",
"ucs-2" or "utf-16le"

Fixes: #8236
PR-URL: #8301
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants