Last active
March 9, 2022 05:05
-
-
Save airtheva/6307570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example of decrypting AES/ECB/PKCS5Padding-encrypted buffer in node.js. | |
// Hope this gist will help you. Feel free to discuss with me. | |
var crypto = require('crypto'); | |
// Change this to fit your needs. | |
// The buffer of your raw password. | |
var keyBuffer = new Buffer('12345678'); | |
// The buffer of your data to be decrypted. | |
var encryptedBuffer = new Buffer('12345678'); | |
// ECB mode won't need IV, so keep it like this and it will work well. | |
var ivBuffer = new Buffer(''); | |
// crypto.createDecipher() receives argument as passpharse, and uses the passpharse to generate raw password and IV. | |
// Which really confuses me a lot. | |
var decipher = crypto.createDecipheriv('aes-128-ecb', keyBuffer, ivBuffer); | |
var chunks = []; | |
chunks.push(decipher.update(encryptedBuffer, 'buffer', 'hex')); | |
chunks.push(decipher.final('hex')); | |
// Use chunks.join('') to combine all parts, and then parse the hex string into Buffer object. | |
var decryptedBuffer = new Buffer(chunks.join(''), 'hex'); | |
// The decryptedBuffer is what you want. | |
// Done. |
Thanks.
you made my day.
Thanks,
Works great, thanks!
Data encryption in Android and decrypting in node.js how this is possible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks.