码迷,mamicode.com
首页 > 系统相关 > 详细

hmac模块使用

时间:2017-12-19 19:58:29      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:print   bbb   body   date   使用   encode   utf-8   模块   new   

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+后面的内容组合起来是一样的,最终结果也不一样,不在举例了。

 

hmac模块使用

标签:print   bbb   body   date   使用   encode   utf-8   模块   new   

原文地址:http://www.cnblogs.com/litzhiai/p/8066005.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!