python与数据加密
2008-12-23 20:27
113 查看
使用Python来做数据加密同样简单,可以使用hashlib或者hmac模块来做数据加密
1、hashlibimport hashlib#创建一个哈希对象md = hashlib.md5()#md = hashlib.sha1()#md = hashlib.sha224()#md = hashlib.sha25()#md = hashlib.sha384()#md = hashlib.sha512()
1.1 hashlib.update(arg)1.2 hashlib.digest() #返回数字形式的哈希1.3 hashlib.hexdigest() #返回16进制的哈希1.4 hashlib.copy()
一般而言,用hashlib.hexdigest()就可以了
2、hmac2.1 hmac.new(key[, msg[, digestmod]])2.2 hmac.update(msg)2.3 hmac.digest()2.4 hmac.hexdigest()2.5 hmac.copy()
要注意,上面的message都要用bytes,使用string不可以
1、hashlibimport hashlib#创建一个哈希对象md = hashlib.md5()#md = hashlib.sha1()#md = hashlib.sha224()#md = hashlib.sha25()#md = hashlib.sha384()#md = hashlib.sha512()
1.1 hashlib.update(arg)1.2 hashlib.digest() #返回数字形式的哈希1.3 hashlib.hexdigest() #返回16进制的哈希1.4 hashlib.copy()
一般而言,用hashlib.hexdigest()就可以了
2、hmac2.1 hmac.new(key[, msg[, digestmod]])2.2 hmac.update(msg)2.3 hmac.digest()2.4 hmac.hexdigest()2.5 hmac.copy()
要注意,上面的message都要用bytes,使用string不可以
相关文章推荐
- python全栈开发-hashlib模块(数据加密)、suprocess模块、xml模块
- python 数据加密以及生成token和token验证
- python2/python3数据加密
- Python对数据加密与解密
- Python描述器descriptor详解
- python对url格式解析的方法
- python处理HTML转义字符
- python进程&线程
- python, web 以及 后台开发
- 初学python(对比java语言不同) 第二篇
- [Lintcode 3sum]三数之和(python,二分)
- python的日志logging模块性能以及多进程
- Python中else语句整理
- 使用boost.python在python调用C++接口(windows)
- python, scipy, theano笔记
- python-web架构
- python中easy_install 卸载已经安装的包
- python tools:将视频的每一帧提取并保存
- Python开发安装的一些常用模块
- python kill process by name