本文實(shí)例講述了Python常見加密模塊用法。分享給大家供大家參考,具體如下:
1. md5模塊
md5.new([arg])     返回一個(gè)md5對(duì)象,如果給出參數(shù),則相當(dāng)于調(diào)用了update(arg)md5.update(arg)   用string參數(shù)arg更新md5對(duì)象md5.digest()         返回16字節(jié)的摘要,由傳給update的string生成,摘要沒有ascii字符md5.hexdigest()    以16進(jìn)制的形式返回摘要
import md5a = 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 shab=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() '63c139b45d59477a85e8438f46fe9ec37cb136ba3.crypt
crypt模塊中就一個(gè)函數(shù),crypt(str,salt) --> string
from crypt import cryptcrypt('passwd','a') 'aaIslqfNH03LA'crypt('passwd','abc') 'ab8RogIKnX0og'crypt('passwd','a') 'aaIslqfNH03LA'PS:關(guān)于加密解密感興趣的朋友還可以參考本站在線工具:
文字在線加密解密工具(包含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
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python加密解密算法與技巧總結(jié)》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選