Vinoth
Vinoth

Reputation: 5785

Node.js - Encryption

I am integrating a payment gateway for my node.js project. They have integration kit in python and i don't have much experience in it. I ported their change from python to javascript. Is this correct ?

Python code:

def encrypt(plainText,workingKey):
        iv = 'hello'
        encDigest = md5.new ()
        encDigest.update(workingKey)
        enc_cipher = AES.new(encDigest.digest(), AES.MODE_CBC, iv)
        encryptedText = enc_cipher.encrypt(plainText).encode('hex')
        return encryptedText

Ported Code (Node.js):

function encrypt(plainText, workingKey){
    var iv = 'hello';
    var encDigest   = crypto.createHash('md5');
    encDigest.update(workingKey);
    var enc_cipher = crypto.createCipheriv('aes-256-cbc', encDigest, iv);
    var encryptedText = enc_cipher.encrypt(plainText).encode('hex');
    return encryptedText;

}

Upvotes: 1

Views: 206

Answers (1)

Brian Baker
Brian Baker

Reputation: 996

Is it not working? The only possible issue I can see is async vs sync. For example the var encDigest = crypto.createHash('md5'); may not be resolved when encDigest.update(workingKey); gets fired.

Upvotes: 1

Related Questions