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

Initialization Vector length in createCipheriv/createeciperiv for aes-128-ecb #10263

Closed
UppaJung opened this issue Dec 14, 2016 · 1 comment
Closed
Labels
crypto Issues and PRs related to the crypto subsystem. question Issues that look for answers.

Comments

@UppaJung
Copy link

UppaJung commented Dec 14, 2016

  • Version: v6.7.0
  • Platform: 64-bit windows
  • Subsystem: crypto

The following node.js code attempts to create a cipher using AES 128 in ECB mode with an initialization vector (IV) filled with 0 bytes.

    let keyBuffer = Buffer.from("DoNotUseUTF8Keys",'utf8');
    let ivBuffer = Buffer.alloc(16); // 16 bytes set to 0
    try {
      let cipher = createCipheriv("AES-128-ECB", keyBuffer, ivBuffer);
    } catch (e)
    {
      console.log(e.message);
    }

When createCipheriv (or createDeciperiv) is called, the node.js code throws "Invalid IV length".

For a 128-bit (16-byte) cipher, AES should have a 16-byte Initialization Vector (IV), so I do not understand why the parameter would yield an exception. (Regardless of whether I'm in error, it would sure be nice to see an exception thrown which says what the correct length is.)

@mscdex mscdex added crypto Issues and PRs related to the crypto subsystem. question Issues that look for answers. labels Dec 14, 2016
@mscdex
Copy link
Contributor

mscdex commented Dec 14, 2016

ECB doesn't utilize an IV, so you should just pass a zero-length Buffer instead for that parameter:

let keyBuffer = Buffer.from("DoNotUseUTF8Keys",'utf8');
let ivBuffer = Buffer.alloc(0);
let cipher = createCipheriv("AES-128-ECB", keyBuffer, ivBuffer);

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. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants