Python常见加密模块用法分析【MD5,sha,crypt模块】
2017-05-24 10:24
1041 查看
本文实例讲述了Python常见加密模块用法。分享给大家供大家参考,具体如下:
1. md5模块
md5.new([arg])返回一个md5对象,如果给出参数,则相当于调用了update(arg)
md5.update(arg)用string参数arg更新md5对象
md5.digest()返回16字节的摘要,由传给update的string生成,摘要没有ascii字符
md5.hexdigest()以16进制的形式返回摘要
import md5 a = md5.new('passwd') a.digest() 'v\xa2\x17;\xe692T\xe7/\xfaMm\xf1\x03\n' a.hexdigest() '76a2173be6393254e72ffa4d6df1030a' a.update('hello world') a.digest() '\xb2\x83f\xb8\x14\xc9\xc6\x19k\x01\xfe\xd8\xd9\x8f\xe0H' a.hexdigest() 'b28366b814c9c6196b01fed8d98fe048'
2.sha 模块
用法同md5一样
import sha b=sha.new('passwd') b.digest() "0'LG\x90;\xd1\xba\xc7c;\xbf\tt1I\xeb\xab\x80_" b.hexdigest() '30274c47903bd1bac7633bbf09743149ebab805f' b.update('hello') b.digest() 'c\xc19\xb4]YGz\x85\xe8C\x8fF\xfe\x9e\xc3|\xb16\xba' b.hexdigest() '63c139b45d59477a85e8438f46fe9ec37cb136ba
3.crypt
crypt模块中就一个函数,crypt(str,salt) --> string
from crypt import crypt crypt('passwd','a') 'aaIslqfNH03LA' crypt('passwd','abc') 'ab8RogIKnX0og' crypt('passwd','a') 'aaIslqfNH03LA'
PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:
文字在线加密解密工具(包含AES、DES、RC4等):
http://tools.jb51.net/password/txt_encode
MD5在线加密工具:
http://tools.jb51.net/password/CreateMD5Password
在线散列/哈希算法加密工具:
http://tools.jb51.net/password/hash_encrypt
在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.jb51.net/password/hash_md5_sha
在线sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.jb51.net/password/sha_encode
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python加密解密算法与技巧总结》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- Python的加密模块md5、sha、crypt使用实例
- python的加密模块(md5,sha,crypt)学习
- Python的加密模块md5、sha、crypt使用实例
- python的加密模块(md5,sha,crypt)学习
- python的加密模块(md5,sha,crypt)学习
- Python subprocess模块常见用法分析
- Python AES加密模块用法分析
- python 之 os 模块的常见用法
- Python中random模块用法实例分析
- python之模块pprint之常见用法
- Python md5与sha1加密算法用法分析
- Python之队列queue模块使用 常见问题与用法
- python开发中module模块用法实例分析
- Python常用模块用法分析
- Python pickle模块用法实例分析
- python实现的AES双向对称加密解密与用法分析
- Python中threading模块join函数用法实例分析
- python的keyword模块用法实例分析
- Python之队列queue模块使用 常见问题与用法
- python的keyword模块用法实例分析