hmac模块使用

hmac模块使用

hashlib : 不可逆加密 
hmac : 不可逆键值对方式加密 
base64: 可逆加密

使用案例如下:

 1 import  hmac
 2 
 3 a=hmac.new('key'.encode('utf-8')) #new 先加密一个key叫做’key‘
 4 a.update('abc'.encode('utf-8'))
 5 a.update('bbb'.encode('utf-8'))
 6 a.update('ccc'.encode('utf-8'))
 7 a.update('ddd'.encode('utf-8'))
 8 print(a.hexdigest())
 9 
10 b=hmac.new('key'.encode('utf-8')) #new 先加密一个key叫做’key‘
11 b.update('abcbbbcccddd'.encode('utf-8'))
12 print(b.hexdigest())

key一致,后面多次添加,最终内容是一样的

key不一致,即使key+后面的内容组合起来是一样的,最终结果也不一样,不在举例了。

 

posted @ 2017-12-19 15:35  大川哥  阅读(788)  评论(0编辑  收藏  举报