#encoding=utf8
#pip install pyDes,安装pyDes库
import base64
from pyDes import *
Des_Key = "12345678"
Des_IV = bytes(Des_Key,encoding = "utf8")
def DesEncrypt(source):
k = des(Des_Key, CBC, Des_IV, pad = None, padmode = PAD_PKCS5)
tmpStr = k.encrypt(source)
tmpStr = base64.b64encode(tmpStr)
return str(tmpStr,"utf8")
def DesDecrypt(source):
k = des(Des_Key, CBC, Des_IV, pad = None, padmode = PAD_PKCS5)
source = base64.b64decode(source)
tmpStr = k.decrypt(source)
return str(tmpStr,"utf8")
print("123加密后是:",DesEncrypt("123"))
print("6u1n1q7jQ5A=解密后是:",DesDecrypt("6u1n1q7jQ5A="))
源码下载:DES加解密.zip
ok
mjj通道