Python对数据加密与解密
2017-05-16 12:35
183 查看
1、base64模块
>>>import base64
>>>s1 = base64.encodestring('Hello world') #加密过程
>>>print s1
>>>SGVsbG8gd29ybGQ=
>>>s2 = base64.decodestring(s1) #解决过程
>>>print s2
>>>Hello world
2、Crypto模块
>>> import Crypto
>>> from Crypto.Cipher import AES
>>> obj = AES.new('This is a key123',AES.MODE_CBC,'This is an IV456')
>>> message = 'The answer is no'
>>> ciphertext = obj.encrypt(message)
>>> ciphertext
'\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1'
>>> obj2 = AES.new('This is a key123',AES.MODE_CBC,'This is an IV456')
>>> obj2.decrypt(ciphertext)
'The answer is no'
>>>
>>>import base64
>>>s1 = base64.encodestring('Hello world') #加密过程
>>>print s1
>>>SGVsbG8gd29ybGQ=
>>>s2 = base64.decodestring(s1) #解决过程
>>>print s2
>>>Hello world
2、Crypto模块
>>> import Crypto
>>> from Crypto.Cipher import AES
>>> obj = AES.new('This is a key123',AES.MODE_CBC,'This is an IV456')
>>> message = 'The answer is no'
>>> ciphertext = obj.encrypt(message)
>>> ciphertext
'\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1'
>>> obj2 = AES.new('This is a key123',AES.MODE_CBC,'This is an IV456')
>>> obj2.decrypt(ciphertext)
'The answer is no'
>>>
相关文章推荐
- C#数据加密与解密 (2)
- 数据加密和解密
- ASP.NET(C#)常用数据加密和解密方法
- 常用数据加密和解密方法汇总
- 【案例】使用PHP的内置函数,通过DES算法对数据加密和解密
- python字符串加密与解密
- DPAPI(Data Protection API) 数据加密和解密
- ASP.NET(C#)常用数据加密和解密方法1
- java实现DES数据加密与解密
- [★] DPAPI(Data Protection API) 数据加密和解密
- 数据加密和解密
- 谈谈关于数据加密,解密及签名的一些问题
- ASP.NET(C#)常用数据加密和解密方法汇总
- 数据加密和解密
- 数据加密与解密
- python与数据加密
- SQL数据加密与解密
- ASP.NET(C#)常用数据加密和解密方法汇总
- asp.net MD5数据加密和解密
- 通过PHP的内置函数,通过DES算法对数据加密和解密