Bootstrap FreeKB - Python (Scripting) - Generate random secret tokens
Python (Scripting) - Generate random secret tokens

Updated:   |  Python (Scripting) articles

secrets can be used to generate random tokens.

#!/usr/bin/python3
import secrets
print(f"bytes   = {secrets.token_bytes(64)}")
print(f"hex     = {secrets.token_hex(64)}")
print(f"urlsafe = {secrets.token_urlsafe(64)}")

 

The above script should print something like this.

bytes   = b'Ji\xd95\xccN\xfeZ<\xc7\xcd\xa5\x11\x9c\x9bAE\x1e\xf2\x1b\xd7\x1cH1\xa7\xd0V\xa8\xd5\x9b\xa4\xb2N=\xd1`C\xfaK\x07\xde{k\x81\xbb=l\x0b% \xb1\xee\xf3\xdc\x11\x0b\xbeZ\x95\xa4\xb7hM\xe8'
hex     = e4d3b241b4e21fb622ec67778a8743cb0e9685352a3ffe448710473a22fdca4a130ff0072b0f4a132bd782fc885386542ba1c3db6d6445582b09d16871c2d0e5
urlsafe = eOZmSlzswfCsE1mvl_77n1pM1c5mpG8LUPJ9C2Hln4SZpKJ4C9rG9e-ps8j7PMqWd2rhOGFwFwHG_lkuZVwFkA

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 0e2f16 in the box below so that we can be sure you are a human.