Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

hashing algorithms in python

>>> from hashlib import blake2b
>>> from hmac import compare_digest
>>>
>>> SECRET_KEY = b'pseudorandomly generated server secret key'
>>> AUTH_SIZE = 16
>>>
>>> def sign(cookie):
...     h = blake2b(digest_size=AUTH_SIZE, key=SECRET_KEY)
...     h.update(cookie)
...     return h.hexdigest().encode('utf-8')
>>>
>>> def verify(cookie, sig):
...     good_sig = sign(cookie)
...     return compare_digest(good_sig, sig)
>>>
>>> cookie = b'user-alice'
>>> sig = sign(cookie)
>>> print("{0},{1}".format(cookie.decode('utf-8'), sig))
user-alice,b'43b3c982cf697e0c5ab22172d1ca7421'
>>> verify(cookie, sig)
True
>>> verify(b'user-bob', sig)
False
>>> verify(cookie, b'0102030405060708090a0b0c0d0e0f00')
False
Comment

PREVIOUS NEXT
Code Example
Python :: HIDING AND ENCRYPTING PASSWORDS IN PYTHON USING ADVPASS 
Python :: traint test split on column id 
Python :: python tk highlightthicknes 
Python :: how to print continuesly in the same line in python 
Python :: simulieren mit python 
Python :: Horizontal stacked percentage bar chart - matplotlib documentation 
Python :: python cheat sheets 
Python :: dropdown menu with selenium python 
Python :: buscar elemento en lista python 
Python :: fix the error when you close turtle screen in your own main loop 
Python :: 1041 uri solution 
Python :: if variable does not contain py 
Python :: insert key in binary tree recursively 
Python :: quit block in python 
Python :: lists as parameters in stats.f_oneway 
Python :: how to return value in new record to odoo 
Python :: examples of function decorators in Python 
Python :: python packing circles 
Python :: python generator cheat sheet download 
Python :: python change type of every element in a dictionary 
Python :: python continue inner for loop 
Python :: how to access a variable from another py file in vs code 
Python :: morris Inorder Traversal python 
Python :: concatenate dataframes using one column 
Python :: Applies a function to all elements of this RDD. 
Python :: python create adictionary randomly assigning clors to categorical vairables 
Python :: randian angle to degrees using numpy 
Python :: qlcdnumber set value python 
Python :: if query empty print python 
Python :: sumx and ABS in power bi 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =