from pyDes import des,PAD_PKCS5,ECB #设置加密时添加的秘钥 DES_SECRET = 'mysecret' #要加密的数据 #ValueError: pyDes can only work with encoded strings, not Unicode. data = '今天天气很好'.encode() # def __init__(self, key, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL): desObj = des(DES_SECRET,ECB,None,padmode=PAD_PKCS5) #加密 myencrypt = desObj.encrypt(data) #解密 mydecrypt = desObj.decrypt(myencrypt) print(myencrypt) print(mydecrypt.decode()) # A:/source/mywebsiteGit/mywebsite/mysite/mysite/testDir/des_secret.py # b'-xae9xedxdc xe2rxb4xf48xedWx17xb3x90Hx0bx85x85x17;x9exfe' # 今天天气很好