I have a problem with using AES decipher for a buffer object and i hope someone have an idea, what i am doing wrong...
MyExample: I have a MySQL table with AES_ENCRYPT for username and password...
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;
Node.JS: I am using node-mysql module to send a query to my datase:
SELECT * FROM Accounts;
Such kind of values are returned for password and username:
<Buffer 07 86 95 ee 77 df 86 50 ae 18 4c d5 3e 48 42 75>
How to decode it with Node.JS decipher method? My tries failed all... I hope AES-128-ECB is choosen correctly...
To deciper something in Node.JS should look like this:
var decipher = crypto.createDecipher('AES-128-ECB', 'password');
var dec = decipher.update(rows[i].username); // an example, value look like <Buffer ...
dec += decipher.final('utf8');
console.log('dec: ' + dec);
Thanks for all helping :)