0
votes

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
1
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 failsxmojmr

1 Answers

1
votes

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.