title: Decrypt MySQL's AES_ENCRYPT in Node.js
body: <p>I have a problem with using AES decipher for a buffer object and i hope someone have an idea, what i am doing wrong...</p>
  
  <p>MyExample:
  I have a MySQL table with AES_ENCRYPT for username and password...</p>
  
  <pre><code>CREATE TABLE Accounts 
  (
      id INT(4) NOT NULL AUTO_INCREMENT,
      username VARBINARY(128) NOT NULL,
      password VARBINARY(128) NOT NULL,
      PRIMARY KEY(id)
  );
  
  DELIMITER |
  CREATE TRIGGER encodeAccounts BEFORE INSERT ON Accounts
  FOR EACH ROW BEGIN
      SET NEW.username = AES_ENCRYPT(NEW.username, 'password');
      SET NEW.password = AES_ENCRYPT(NEW.password, 'password');
  END;
  </code></pre>
  
  <p>Node.JS:
  I am using node-mysql module to send a query to my datase: </p>
  
  <pre><code>SELECT * FROM Accounts;
  </code></pre>
  
  <p>Such kind of values are returned for password and username:</p>
  
  <pre><code>&lt;Buffer 07 86 95 ee 77 df 86 50 ae 18 4c d5 3e 48 42 75&gt;
  </code></pre>
  
  <p>How to decode it with Node.JS decipher method? My tries failed all... 
  I hope AES-128-ECB is choosen correctly...</p>
  
  <p>To deciper something in Node.JS should look like this:</p>
  
  <pre><code>var decipher = crypto.createDecipher('AES-128-ECB', 'password');
  var dec = decipher.update(rows[i].username); // an example, value look like &lt;Buffer ...
  dec += decipher.final('utf8');
  console.log('dec: ' + dec);
  </code></pre>
  
  <p>Thanks for all helping :)</p>