python如何复现DES3加密

发布时间 2023-08-15 08:42:06作者: 字母一哥
import base64
from Crypto.Cipher import DES3

BS = 8
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)

# 3DES的MODE_CBC模式下只有前24位有意义
key = b'appapiche168comappapiche168comap'[0:24]
iv = b'appapich'
plaintext = pad("9f5c0af5-d408-355e-a390-b751c50e7500|30288955700359|363891").encode("utf-8")
# 使用MODE_CBC创建cipher
cipher = DES3.new(key, DES3.MODE_CBC, iv)
result = cipher.encrypt(plaintext)
res = base64.b64encode(result)
print(res)
# e6FYJGvcksQmRAEAoLvdgHQkCJmbaXzSjIgjFcQ2k4zSB4F94E32UF7QRuJf HPVzjrLzMnetjKcf2B2o2Kd3ag==