Generating keys securely with the secrets and hashlib modules
In this section, we are going to review the main modules Python provides for generating keys and passwords in a secure way.
Generating keys securely with the secrets module
The secrets module is used to generate cryptographically strong random numbers, suitable for managing data such as passwords, user authentication, security tokens, and related secrets.
In general, the use of random numbers is common in various scientific computing applications and cryptographic applications. With the help of the secrets
module, we can generate reliable random data that can be used by cryptographic operations.
In particular, secrets
are recommended to be used preferably over the generation of pseudo-random numbers using the random
module, which is designed for modeling and simulation, and not for security or cryptography.
The secrets
module derives its implementation from the os.urandom()
and SystemRandom()
methods that...