最近要做签名(hmac-sha1算法),但不同语言实现效果不一致,纠结了一阵
网上有一版,但试过后发现不靠谱(大概方式如此:http://blog.csdn.net/iefreer/article/details/7829109)
php的方式
(php手册上就有)
$sig= base64_encode(hash_hmac("sha1", $originStr, $secretKey, true));
python的方式
(参考http://stackoverflow.com/questions/8338661/implementaion-hmac-sha1-in-python)
from hashlib import sha1
import hmac
import binascii
hashed = hmac.new(key, raw, sha1)
sig = binascii.b2a_base64(hashed.digest())[:-1]