Python中hashlib模組,Pythonhashlib模組

來源:互聯網
上載者:User

Python中hashlib模組,Pythonhashlib模組
Python中hashlib模組

該模組主要用於資料加密。加密方式有md5、sha224、sha384、sha512、sha1、sha3_224、sha3_256、sha3_384、sha3_512等等加密方式。它通過一個函數,把任意長度的資料轉換為一個長度固定的資料串(通常用16進位的字串表示)。不同加密方法的使用都是一樣的,故在此只樣本用md5加密的代碼:

import hashlib       

m = hashlib.md5()

m.update('hello'.encode('utf8'))   #對資料‘hello’進行md5加密

print(‘m=’,m.hexdigest())      #以十六進位數將加密後的結果列印出來。m= 5d41402abc4b2a76b9719d911017c592

b.update('he'.encode('utf8'))

b.update('llo'.encode('utf8'))

print('b=',b.hexdigest())             #分步加密和直接加密,結果一樣.b= 5d41402abc4b2a76b9719d911017c592

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.