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

Urldecode string (LUA)
FFMPEG Convert YUV444p to YUV420p (BASH)
Forcing FFMPEG to honour segment length in HLS Stream Creator (BASH)
Force CURL to place request to a specific IP (BASH)
Set a variable only if it is undefined (Javascript)
Ignore query string with Nginx caching proxy (NGinx)
Get breakdown of UK and non-UK votes for a Parliamentary Petition (Python)
Decompress Mozilla Firefox jsonlz4 bookmark backup files (Python)
Setting Git author details for a single repo (Git)
Checking Virtual Machine Resource Allocations with Libvirt (BASH)

Copyright © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion