python pyDes加密解密
2019-10-03 python 3918
import base64 from pyDes import * #pip install pyDes class DEncry: def __init__(self): self.Des_Key = "12345678" # Key self.Des_IV = "abcdefgh" # 自定IV向量 # 使用DES加base64的形式加密 def encrypt(self, s): k = des(self.Des_Key, CBC, self.Des_IV, pad=None, padmode=PAD_PKCS5) EncryptStr = k.encrypt(s) # EncryptStr = binascii.unhexlify(k.encrypt(str)) return base64.b64encode(EncryptStr).decode() # 转base64编码返回 # des解码 def decrypt(self, s): s = base64.b64decode(s) k = des(self.Des_Key, CBC, self.Des_IV, pad=None, padmode=PAD_PKCS5) DecryptStr = k.decrypt(s,padmode=PAD_PKCS5) return DecryptStr.decode() if __name__ =="__main__": de = DEncry() passwd = de.encrypt("99999999") print("passwd: %s" % passwd) ret = de.decrypt(passwd) print("result: %s" % ret)
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论