Python中使用hashlib进行加密的简单使用

 1 import hashlib
 2 '''
 3 
 4 原文= ’字符串‘
 5 哈希加密对象 = hashlib.加密算法( 原文.encode('utf-8') )
 6 密文 = 哈希加密对象.hexdigest()     #密文是字符串
 7 
 8 '''
 9 
10 password = '123'    #原文
11 secret = hashlib.sha1(password.encode('utf-8')).hexdigest() #获得密文
12 print(secret)
13 
14 
15 secret = hashlib.sha256(password.encode('utf-8')).hexdigest() #获得密文
16 print(secret)
17 
18 
19 secret = hashlib.md5(password.encode('utf-8')).hexdigest() #获得密文
20 print(secret)

 

posted @ 2017-09-21 19:52  稀里糊涂林老冷  阅读(545)  评论(0编辑  收藏  举报