nodejs / node-v0.x-archive

Moved to https://github.com/nodejs/node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

atstoyanov opened this issue · comments

Hello

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');

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

According to the documentation:
https://nodejs.org/api/crypto.html#crypto_decipher_update_data_input_encoding_output_encoding

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' nn lib/internal/util.js that can be used to normalize the encoding.