遵循Perl代码的Python等价物是什么?
hmac_md5_hex($login . "^" . $seq . "^" . $time . "^" . $amo . "^", $CryptoKey);
Python hashlib.md5似乎没有采用"加密密钥"参数.它只接受1个参数.
您必须将hmac模块与md5或sha一起使用.默认情况下它使用md5:
In [1]: import hmac, hashlib In [2]: hmac.new('key', 'msg').hexdigest() Out[2]: '18e3548c59ad40dd03907b7aeee71d67' In [3]: hmac.new('key2', 'msg').hexdigest() Out[3]: 'a4bde113179bc2a7c6ac9ad7309ea073' In [4]: hmac.new('key', 'msg', hashlib.sha256).hexdigest() Out[4]: '2d93cbc1be167bcb1637a4a23cbff01a7878f0c50ee833954ea5221bb1b8c628'
您的示例可能类似于:
hmac.new(CryptoKey, '^'.join([login, seq, time, amo]), hashlib.md5).hexdigest()