首先,在python中,您可以简单地使用hmac模块:>>> import hmac
>>> hmac.new("9T5zhB4sTNGxMJ-iDdO-Ow"+"8rdp7erdig0m6aa72lhanvuk01"+"pizza1", "1387797294").hexdigest()
'9036a1a3f654aefeab426e9f7e17288e'
其次,您的C代码不实现HMAC算法,而只是返回一个MD5散列。
python的等价物是
^{pr2}$
您可以在C中找到HMAC算法的实现,例如at CodePlex。在
从项目页面:Project Description
This is a simple implementation of the MD5
cryptographic hashing algorithm and HMAC-MD5. This class consists of
fully transparent C# code, suitable for use in .NET, Silverlight and
WP7 applications.
另外,我还提出了另一个简单的实现方法:string key = "9T5zhB4sTNGxMJ-iDdO-Ow" + "8rdp7erdig0m6aa72lhanvuk01" + "pizza1";
string message = "1387797294";
var encoding = Encoding.UTF8;