hmac模块使用

Posted litzhiai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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+后面的内容组合起来是一样的,最终结果也不一样,不在举例了。

 

以上是关于hmac模块使用的主要内容,如果未能解决你的问题,请参考以下文章

Node.js 内置模块crypto加密模块 HMAC

Python之hmac模块的使用

hash模块 hashlib 和hmac

nodeJS之crypto模块md5和Hmac加密

如何在matlab中使用base64输出重现相同的python hmac

python hmac.new示例