-
-
Save vikrambiwal/a5de9547e9f26e30134a74e6fb309dff to your computer and use it in GitHub Desktop.
Nodejs encryption and decryption for ccavenue (aes-128-cbc)
This file contains 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
var crypto = require('crypto'); | |
exports.encrypt = function (plainText, working_key) { | |
const m = crypto.createHash('md5'); | |
m.update(working_key); | |
const key = m.digest(); | |
const iv = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'; | |
const cipher = crypto.createCipheriv('aes-128-cbc', key, iv); | |
let encoded = cipher.update(plainText, 'utf8', 'hex'); | |
encoded += cipher.final('hex'); | |
return encoded; | |
}; | |
exports.decrypt = function (encText, working_key) { | |
const m = createHash('md5'); | |
m.update(working_key); | |
const key = m.digest(); | |
const iv = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'; | |
const decipher = createDecipheriv('aes-128-cbc', key, iv); | |
let decoded = decipher.update(encText, 'hex', 'utf8'); | |
decoded += decipher.final('utf8'); | |
return decoded; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment