Skip to content

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

Closed
@atstoyanov

Description

@atstoyanov
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions