在很多登陆接口中都经常遇见签名,而常见的签名都是对多个key值组合起来后进行md5.
在python中可以通过hashlib库来实现md5加密。如下对一个字符串进行md5
#/usr/bin python3
# _*_ coding: utf-8 _*_
import hashlib
def getMd5(strValue):
hashMd5 = hashlib.md5()
hashMd5.update(strValue.encode("utf-8"))
return hashMd5.hexdigest()
那么同样的原理对字典值拼接进行md5加密,只要处理了字典值拼接就可以,如下
#/usr/bin python3
# _*_ coding: utf-8 _*_
import hashlib
def getDictValueMd5(dictData):
hashMd5 = hashlib.md5()
strDictValue = ""
if isinstance(dictData, dict):
for value in dictData.values():
strDictValue += str(value)
hashMd5.update(strDictValue.encode("utf-8"))
return hashMd5.hexdigest()
else:
print("输入不是字典")
return 0