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.

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 © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, yr4pnhounvdybotb.onion and snippets.6zdgh5a5e6zpchdz.onion