python M2Crypto HMAC SHA1

时间:2012-08-29 11:29:13

标签: python openssl hmac

我必须以下列方式创建HMAC_SHA1哈希:

auth_reponse = HMAC_SHA1(key=session_id, data=decypted_challenge)

我如何使用M2Crypto执行此操作?

1 个答案:

答案 0 :(得分:3)

尝试:

from M2Crypto.EVP import HMAC
import base64

hmac = HMAC(session_id,'sha1')
hmac.update(decypted_challenge)

auth_response = base64.encodestring(hmac.digest()) #Base64 format

或:

auth_response = hmac.digest() #Binary format

问候!