Python DES 加密解密,就是大家所谓想要的那个非常快速的方法
2015-05-07 18:15
555 查看
这个要借助Crypto.Cipher这个插件来实现的,引用后只需要写如下代码即可
from Crypto.Cipher import DES class MyDESCrypt: key = chr(11)+chr(11)+chr(11)+chr(11)+chr(11)+chr(11)+chr(11)+chr(11) iv = chr(22)+chr(22)+chr(22)+chr(22)+chr(22)+chr(22)+chr(22)+chr(22) def __init__(self,key='',iv=''): if len(key)> 0: self.key = key if len(iv)>0 : self.iv = iv def ecrypt(self,ecryptText): try: cipherX = DES.new(self.key, DES.MODE_CBC, self.iv) pad = 8 - len(ecryptText) % 8 padStr = "" for i in range(pad): padStr = padStr + chr(pad) ecryptText = ecryptText + padStr x = cipherX.encrypt(ecryptText) return x.encode('hex_codec').upper() except: return "" def decrypt(self,decryptText): try: cipherX = DES.new(self.key, DES.MODE_CBC, self.iv) str = decryptText.decode('hex_codec') y = cipherX.decrypt(str) return y[0:ord(y[len(y)-1])*-1] except: return ""
相关文章推荐
- 异或加密法 在对文本进行简单加密的时候,可以选择用一个n位的二进制数,对原文进行异或运算。 解密的方法就是再执行一次同样的操作。
- Python字符串加密解密方法总结
- Java加密/解密算法快速入门上篇[包括MD5、BASE64、DES、RSA等]
- Java和C#交叉加密解密方法(DES)
- DES、AES加密解密的方法
- python中base64加密解密方法实例分析
- python字符串加密解密的三种方法分享(base64 win32com)
- c# DES 加密解密方法
- Java加密解密快速入门下篇【包括MD5、BASE64、DES、RSA等算法】
- 用python实现DES加解密,并附带EBC和CBC两种分组加密模式
- Java加密解密快速入门上篇【包括MD5、BASE64、DES、RSA等算法】
- python 中的一些加密解密方法
- Java加密解密快速入门上篇【包括MD5、BASE64、DES、RSA等算法】
- C# 與JAVA 共用的DES 加密解密方法
- Java加密和C#解密=>DES方法
- Python实现对字符串的加密解密方法示例
- python字符串加密解密的三种方法分享(base64 win32com)
- 目前大家对Python都有一个共识,就是他对测试非常有用,自动化测试里Python用途也很广,但是Python到底怎么进行自动化测试呢?今天就简单的向大家介绍一下怎么使用Python进行自动化测试
- Java加密解密快速入门上篇【包括MD5、BASE64、DES、RSA等算法】