From the course: Python Standard Library Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Cryptographic random operations

Cryptographic random operations - Python Tutorial

From the course: Python Standard Library Essential Training

Start my 1-month free trial

Cryptographic random operations

- So earlier in the chapter I talked a little bit about the difference between plain, random number generators and those that were cryptographically secure. Starting with Python 3.6, there's a module named "Secrets" which provides access to functions that are useful for sensitive needs, such as generating passwords, and security tokens, and other related types of data. The os module contains a function named "urandom" that forms the basis for the secrets module functions. So this function uses a platform-specific way for generating secure, random numbers. I'm not going to go into that level of detail here, you can refer to the mybrary docs to learn more about this. But let's just give that function a quick try. So, I'm going to write result= os.urandom, and it takes a size argument so I'm going to ask for 8 bytes and then I'm going to print the hex value of each byte for the byte in the result sequence. When I run this, you can see the result here. These are the random bytes that were…

Contents