基本操作
#!/usr/bin/env python # encoding: utf-8 """ @author: Irving Shi """ import base64 from pyDes import des, CBC, PAD_PKCS5 Des_Key = "_361Du$Z" Des_IV = [1, 2, 3, 4, 5, 6, 7, 8] def des_encrypt(password): k = des(Des_Key, CBC, Des_IV, pad=None, padmode=PAD_PKCS5) encrypt_str = k.encrypt(password) return base64.b64encode(encrypt_str).decode() def des_decrypt(password): password = base64.b64decode(password) k = des(Des_Key, CBC, Des_IV, pad=None, padmode=PAD_PKCS5) decrypt_str = k.decrypt(password, padmode=PAD_PKCS5) return decrypt_str.decode() if __name__ == "__main__": passwd = des_encrypt("1") print(passwd) ret = des_decrypt(passwd) print(ret)