title: node.js Decipher AES 128 ECB
body: <p>I try to decipher a base64 format token with AES 128-ecb on node.</p>
  
  <p><strong>key</strong>: ed9d26Z0JES0X52Q (changed some character, but a length is correct)</p>
  
  <p><strong>token</strong>: O4girrZ2YeLSE1sZ4FSIvp3Edm1GiwBLHmvDIEYCf+xkvbxP6EfYjy+PEB2kaYe0606EyPmlCC0iExVRq9e3Iw==</p>
  
  <pre><code>  decodeToken(token) {
      var key = new Buffer(exchangeKey, 'hex')
      var encrypted = new Buffer(token, 'base64')
      decipher = crypto.createDecipheriv("aes-128-ecb", key, '')
      decipher.setAutoPadding(false)
      result = decipher.update(encrypted).toString();
      return result;
    }
  </code></pre>
  
  <p>gives:</p>
  
  <blockquote>
    <p>crypto.js:239   this._handle.initiv(cipher, toBuf(key), toBuf(iv));
                   ^</p>
    
    <p>Error: Invalid key length
        at Error (native)
        at new Decipheriv (crypto.js:239:16)
        at Object.Decipheriv (crypto.js:236:12)</p>
  </blockquote>
  
  <p>After some searching I found this:</p>
  
  <pre><code>// https://github.com/nodejs/node-v0.x-archive/issues/4744#issuecomment-25460050
  var aesEcb = new MCrypt('rijndael-128', 'ecb')
  aesEcb.open(exchangeKey);
  var ciphertext = new Buffer(token, 'base64');
  var plaintext = aesEcb.decrypt(ciphertext).toString();
  return plaintext
  </code></pre>
  
  <p>what gives back</p>
  
  <p><strong>f9712fa5-da4a-49fe-b81f-b48d8cfabf91275RAODW24RS</strong></p>
  
  <p>what looks like the expected format and length, but notice the wired characters at the end.</p>
  
  <p>I could use this solution too (and trim the extra characters), but I want to</p>
  
  <ul>
  <li>know what are those characters</li>
  <li>cross reference the two results</li>
  <li>use only one npm package (crypto) </li>
  </ul>