Python模組學習筆記— —hashlib

來源:互聯網
上載者:User

標籤:python   加密   雜湊   

hashlib是涉及安全散列和訊息摘要,提供多個不同的密碼編譯演算法介面,如SHA1、SHA224、SHA256、SHA384、SHA512、MD5等。

常用屬性

hashlib.algorithms
列出所有密碼編譯演算法

h.digest_size
產生的散列位元組大小。

h.block_size
雜湊內部塊的大小

常用方法

hash.new([arg])
建立指定加密模式的hash對象

hash.update(arg)
更新雜湊對象以字串參數。如果同一個hash對象重複調用該方法,m.update(a); m.update(b) 等價於 m.update(a+b)

hash.digest()
返回摘要,作為位元據字串值。

hash.hexdigest()
返回摘要,作為十六進位資料字串值

hash.copy()
複製

代碼執行個體
import hashlibmd5 = hashlib.md5() md5.update("I am Sin_Geek")  print md5.digest()  print md5.hexdigest() print ‘block_size:‘, md5.block_sizeprint ‘digest_size:‘, md5.digest_size

import hashlibprint ‘-‘ * 25, ‘更簡潔版本‘, ‘-‘ * 25print hashlib.new("md5", "I am Sin_Geek").hexdigest()

import hashliba = "I am Sin_Geek"print hashlib.md5(a).hexdigest()print hashlib.sha1(a).hexdigest()print hashlib.sha224(a).hexdigest()print hashlib.sha256(a).hexdigest()print hashlib.sha384(a).hexdigest()print hashlib.sha512(a).hexdigest()

Python模組學習筆記— —hashlib

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.