Decrypt MySQL's AES_ENCRYPT in Node.js -


I have a problem in using AES to understand the buffer object and I hope someone has an idea, I What is wrong ..

My example: I have a MySQL table with AES_ENCRYPT for username and password ...

  Create a tablet account (ID INT (4) No, tap AUTENCcmment, username wizardry (128) noise, password wiredini (128) faucet, primary key ID; DELIMITER | Create Trigger Encodings Register for accounts per line before INR SET NEW.USername = AES_ENCRYPT (NEW.username, 'password'); SET NEW.password = AES_ENCRYPT (new password, 'password'); End;   

Node.js: I'm using the node mysql module to send a question to my datase:

  select from accounts;   

Such types of values ​​are coming back for the password and username:

    

How to interpret it with node. How to understand JS? All my efforts fail ... I hope that AES 128-ECB is selected correctly ...

Some deciper in Node.js should look like this: Decipher on

  = crypto.createDecipher ('AES-128-ECB', 'password'); Var dec = decipher.update (lines [i] .username); // An example, value & lt; Looks like buffer ... dec + = decipher.final ('utf8'); Console.log ('dec:' + dec);   

Thanks for all help :)

be your password Should be converted in the same way that MySQL internally will do it. For a higher password, a 16-bit-length password should have a pad with XORd and 0-bytes. This function should work:

  convert the crypt of the function (straki) {var newKey = new buffer ([0,0,0,0,0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0,0,0,0,0]); Strkey = new buffer (strkey); (Var i = 0; i & lt; strkey.length; i ++) for newKey [i% 16] ^ = strkey [i]; New return; }  MySQL-compatible encryption  - Note that with an empty IV to use "createCipheriv" (CreateCipher creates a self-IV which is not the same as in MySQL)  
  var c = crypto.createCipheriv ( "AES 128-ECB", convertCryptKey ( "MyPassword"), "" ); Var crypted = c.update (Take a tour at 'galaxytrek.com :)', 'utf8', 'hex') + c.final ('hex'); Console.log (crypted.toUpperCase ()); & Gt; & Gt; 92068A5DAECE1E080EF4BA08A45CFF8D2262401F988A9241F1E4CEAAAB80BEAF7E0B50A1D5FD57CA56E92621622F018D   

Which is the same way:

  mysql & gt; Select hex (aes_encrypt ('Take a tour at galaxytrek.com :)', 'myPassword')); + ------------------------------------------------- ------------------------------------------------- + | Hex (aes_encrypt ('Take a tour at galaxytrek.com :)', 'myPassword')) | + ------------------------------------------------- ------------------------------------------------- + | 92068A5DAECE1E080EF4BA08A45CFF8D2262401F988A9241F1E4CEAAAB80BEAF7E0B50A1D5FD57CA56E92621622F018D | + ------------------------------------------------- ------------------------------------------------- +   

decryption

  var dc = crypto.createDecipheriv ( "aes-128-ecb", convert Kriptke ( "myPassword" ), ""); Var decrypted = dc.update ('92068A5DAECE1E080EF4BA08A45CFF8D2262401F988A9241F1E4CEAAAB80BEAF7E0B50A1D5FD57CA56E92621622F018D', 'hex', 'utf 8') + dc.final ('utf8'); Console.log (decrypted); & Gt; & Gt; Travel in Galeksitrek dot com. :)    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -