Created
August 25, 2016 18:55
-
-
Save hfukada/bbdee14e6bb098d73b6ce732bb2a2379 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_nonce(): | |
"""Generates a random string of bytes, base64 encoded""" | |
length = 64 | |
string = base64.b64encode(os.urandom(length), altchars=b'-_') | |
b64len = 4 * min(length, 3) | |
if length % 3 == 1: | |
b64len += 2 | |
elif length % 3 == 2: | |
b64len += 3 | |
return string[0:b64len].decode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment