I'm trying to integrate a 3rd party payment gateway (CCAvenue
) in Django 1.11, Python 3.5.2
The reference code provided by the 3rd party uses the deprecated library md5 to encrypt texts.
from Crypto.Cipher import AES
import md5
def pad(data):
length = 16 - (len(data) % 16)
data += chr(length)*length
return data
def encrypt(plainText,workingKey):
iv = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
plainText = pad(plainText)
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
How do I make the above encrypt()
method Python 3 compatible using the hashlib
library of Python 3? Can you post the whole method?