Skip to Content
Mastering Python for Networking and Security
book

Mastering Python for Networking and Security

by José Manuel Ortega
September 2018
Intermediate to advanced
426 pages
10h 46m
English
Packt Publishing
Content preview from Mastering Python for Networking and Security

Using passwords with the fernet package

It is possible to use passwords with Fernet. To do this, you need to run the password through a key-derivation function, such as PBKDF2HMAC.

PBKDF2 (Password Based Key Derivation Function 2) is typically used for deriving a cryptographic key from a password.

More information about key derivation functions can be found at https://cryptography.io/en/latest/hazmat/primitives/key-derivation-functions/.

In this example, we are using this function to generate a key from a password, and we use that key to create the Fernet object we will use for encrypting and decrypting data. In this case, the data to encrypt is a simple message string. We can use the verify() method, which checks whether deriving a new key ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Networking and Security - Second Edition

Mastering Python for Networking and Security - Second Edition

José Manuel Ortega
Python for Cybersecurity

Python for Cybersecurity

Howard E. Poston, III

Publisher Resources

ISBN: 9781788992510Supplemental Content