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

"des3" crypto Error: Invalid IV length #15062

Closed
mohanen opened this issue Aug 28, 2017 · 1 comment
Closed

"des3" crypto Error: Invalid IV length #15062

mohanen opened this issue Aug 28, 2017 · 1 comment
Labels
crypto Issues and PRs related to the crypto subsystem. question Issues that look for answers. wrong repo Issues that should be opened in another repository.

Comments

@mohanen
Copy link

mohanen commented Aug 28, 2017

Version: v6.11.0
Platform: Linux econ-pc 4.4.0-79-generic #100~14.04.1-Ubuntu SMP Fri May 19 18:36:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Error

crypto.js:194
  this._handle.initiv(cipher, toBuf(key), toBuf(iv));
               ^

Error: Invalid IV length
    at Error (native)
    at new Cipheriv (crypto.js:194:16)
    at Object.Cipheriv (crypto.js:192:12)
    at encrypt3DES (/home/mohanen/Desktop/myApp/index.js:47:29)
    at Object.<anonymous> (/home/mohanen/Desktop/myApp/index.js:29:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

my code

function encrypt3DES (string){
    let iv = Crypto.randomBytes(16);
    let salt = "foobar";
    let hash = Crypto.createHash("sha1");

    hash.update(salt);

    let key = hash.digest().slice(0, 16);

    let encryption = Crypto.createCipheriv("des3", key, iv);

    let cipher = encryption.update(string, "utf8", "base64");
    cipher += cipher.final('base64');

    console.log("[" + string + "] => [" + cipher + "]");
}

trying to write a simple function that encrypts a given string in 3DES-CBC

@bnoordhuis bnoordhuis added crypto Issues and PRs related to the crypto subsystem. question Issues that look for answers. wrong repo Issues that should be opened in another repository. labels Aug 28, 2017
@bnoordhuis
Copy link
Member

'des3' is 3DES in ECB mode, not CBC. Check node -p 'crypto.getCiphers()' to see what is supported.

I'll close this as it's not a node.js bug. If you have further questions, please post them to the help repo.

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. wrong repo Issues that should be opened in another repository.
Projects
None yet
Development

No branches or pull requests

2 participants