openssl rand -base64 32 what is the equivalent in python
Question:
I would like to create a similar random base64 encoded string of 32 bytes, as
openssl rand -base64 32
in python
Can anyone help with, how this is done?
Answers:
In python 3.6+:
from secrets import token_bytes
from base64 import b64encode
print(b64encode(token_bytes(32)).decode())
See https://docs.python.org/3/library/secrets.html for token security details.
I would like to create a similar random base64 encoded string of 32 bytes, as
openssl rand -base64 32
in python
Can anyone help with, how this is done?
In python 3.6+:
from secrets import token_bytes
from base64 import b64encode
print(b64encode(token_bytes(32)).decode())
See https://docs.python.org/3/library/secrets.html for token security details.