Generate a SHA1-HMAC (Python)

SHA1-HMAC's are often used by API's (and in tokenisation) as a means to prove control over a shared secret. They allow proof of control without sending the secret over the network.

Similar To

Details

  • Language: Python

Snippet

from hashlib import sha1
import hmac

def createSha1HMAC(signstr,secret):
    ''' Create a SHA1-HMAC of signstr
    '''
    hashedver = hmac.new(secret,signstr,sha1)
    return hashedver.digest().encode('hex')

Usage Example

createSha1HMAC('I Will Sign This String','MySuperS3cr37 key')