def Encrypt(toEncrypt, key, useHashing): toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt.encode("utf-8")) if useHashing: keyArray = hashlib.md5(key.encode("utf-8")).digest() pass else: keyArray = key.encode("utf-8") pass tdes = TripleDes(keyArray, ECB) resultArray = tdes.encrypt(toEncryptArray) return base64.b64encode(resultArray) pass
def Decrypt(cipherString, key, useHashing): ##cipherString = "tBs5HSwlA4UHXPUR0vSvOdAkICGtM5LzbZ/Nu/UD/JPVRXJlDRlRUg=="; ##key = "2DCA8D969C6740AD92DA9BA6"; toEncryptArray = base64.b64decode(cipherString) if useHashing: keyArray = hashlib.md5(key.encode("utf-8")).digest() pass else: keyArray = key.encode("utf-8") pass tdes = TripleDes(keyArray, ECB) resultArray = tdes.decrypt(toEncryptArray) return resultArray[0:32]