python des 加密
from pyDes import des, CBC, PAD_PKCS5 import binascii # 秘钥 KEY = '这里使用8个字符秘钥' def des_encrypt(s): """ DES 加密 :param s: 原始字符串 :return: 加密后字符串,16进制 """ secret_key = KEY iv = secret_key k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5) en = k.encrypt(s, padmode=PAD_PKCS5) return binascii.b2a_hex(en).decode() def des_descrypt(s): """ DES 解密 :param s: 加密后的字符串,16进制 :return: 解密后的字符串 """ secret_key = KEY iv = secret_key k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5) de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5) return de.decode() s = 'kKCtFQbVXOg0+Bzy3h1cAQ==' enc = des_encrypt(s) print(enc) des = des_descrypt(enc) print(des)