Generate a SHA1-HMAC



Published: 2018-04-12 08:35:04 +0000
Categories: Python,

Language

Python

Description

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

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')

Keywords

HMAC, SHA1, generate, token, mint, create,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter