赞
踩
首先来看一段HmacSHA1加密和SHA1加密的代码
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Created on 1/31/18 10:03 AM @author: Chen Liang @function: HmacSHA1 vs SHA1 """ import sys reload(sys) sys.setdefaultencoding('utf-8') import hashlib import hmac def sha1(msg): """ sha1加密 :param msg: :return: 长度40位的摘要信息 """ sha = hashlib.sha1() sha.update(msg) return sha.hexdigest() def hmac_sha1(key, msg): """ hmac sha1加密 :param key: 密钥 :param msg: 待加密消息 :return: 长度40位的摘要信息 """ m = hmac.new(key, msg, hashlib.sha1) return m.hexdigest() print hmac_sha1('FKEwTiz9Te0FWlqkS4g8hEdqAsPZfdR4', 'me') print sha1('me')
输出结果为
1db0e9132a8dff51e3a4d47497e29a500087da9a
b1c1d8736f20db3fb6c1c66bb1455ed43909f0d8
从结果中可以发现,HmacSHA1算法和SHA1算法都
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。