0

I have to decode a rijndael 128 string

the string can be successfully using this online tool http://www.tools4noobs.com/online_tools/decrypt/ with theses parameters :

  • Algorythm rijndael 128
  • Mode : CBC
  • Decode the output using base64

I have to decode this using node.js and crypto module

Here is my code

function Token(TokenBase64 )
{

   var crypto  = require('crypto');

   this.TokenToCheck = new Buffer(TokenBase64,'base64').toString();
   this.GameKey      = 'xxxxxxxxxxxxxxxxx'; 

   var cryptKey =  crypto.createHash('sha256').update(this.GameKey).digest()

   this.decipher  = crypto.createDecipheriv('aes-128-cbc', cryptKey, '12345678901234561234567890123456');

   var dec = this.decipher.update( this.TokenToCheck);

   dec += this.decipher.final();

   return dec;
}

module.exports = Token;

The error output by this code when called is :

Error: DecipherInitIv error at new Decipheriv (crypto.js:360:17) at Object.Decipheriv (crypto.js:357:12) at new Token
Nico AD
  • 1,657
  • 4
  • 31
  • 51
  • I'd use crypto.getDeciphers() to check the list of those available. Make sure the deciper name is not case sensitive and use some kind of debugger to step inside the crypt.js code to find out more about why the initialization fails – xmojmr Apr 19 '14 at 11:29

1 Answers1

1

The size of your IV is 32 characters (which will probably be used as 32 bytes). AES always uses a 128 bit block size and the IV for CBC is always the size of a single block. So you've got 16 characters too many.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • Note that using a static, non-random IV for CBC does not make sense, unless you never reuse your key. – Maarten Bodewes Apr 19 '14 at 13:56
  • you re right, I now more close to the result with this code : var decipher = crypto.createDecipheriv(algorithm, new Buffer(this.GameKey) , new Buffer('0000000000000000')) decipher.setAutoPadding(false); var buf = decipher.update(new Buffer(TokenBase64,'base64'), 'hex'); buf += decipher.final('utf8'); about IV , i m just porting and old PHP code which use 0*16 as IV. I m not responsible on the encryptation, which is done by a third party – Nico AD Apr 22 '14 at 11:39
  • Glad you've got the IV working N-AccessDev, good luck with the rest of it :) – Maarten Bodewes Apr 22 '14 at 12:29