我正在尝试在Flask 0.12.2,Python 3.6.1中集成第三方支付网关(CCAvenue)。
第三方提供的参考代码使用了已弃用的库md5来加密文本。
我已经在Existing Solution in Django中找到了迁移的解决方案。但是,我需要相同的Flask版本代码。
python参考方案
我有解决方案,这是代码
from Crypto.Cipher import AES
import hashlib
from binascii import hexlify, unhexlify
def pad(data):
length = 16 - (len(data) % 16)
data += chr(length)*length
return data
def unpad(data):
return data[0:-ord(data[-1])]
def encrypt(plainText, workingKey):
iv = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
plainText = pad(plainText)
bytearrayWorkingKey = bytearray()
bytearrayWorkingKey.extend(map(ord, workingKey))
enc_cipher = AES.new(hashlib.md5(bytearrayWorkingKey).digest(), AES.MODE_CBC, iv)
return hexlify(enc_cipher.encrypt(plainText)).decode('utf-8')
def decrypt(cipherText, workingKey):
iv = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
encryptedText = unhexlify(cipherText)
bytearrayWorkingKey = bytearray()
bytearrayWorkingKey.extend(map(ord, workingKey))
decCipher = AES.new(hashlib.md5(bytearrayWorkingKey).digest(), AES.MODE_CBC, iv)
return unpad(decCipher.decrypt(encryptedText).decode('utf-8'))
Python sqlite3数据库已锁定 - python我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…
Python pytz时区函数返回的时区为9分钟 - python由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…
用大写字母拆分字符串,但忽略AAA Python Regex - python我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…
如何打印浮点数的全精度[Python] - python我编写了以下函数,其中传递了x,y的值:def check(x, y): print(type(x)) print(type(y)) print(x) print(y) if x == y: print "Yes" 现在当我打电话check(1.00000000000000001, 1.0000000000000002)它正在打印:<…
Python:检查新文件是否在文件夹中[重复] - pythonThis question already has answers here: How do I watch a file for changes? (23个答案) 3年前关闭。 我是python的新手,但是我尝试创建一个自动化过程,其中我的代码将侦听目录中的新文件条目。例如,某人可以手动将zip文件复制到一个特定的文件夹中,并且我希望我的代码能够在文件完全…