PBKDF2 | Practical Cryptography for Developers (2024)

PBKDF2 is a simple cryptographic key derivation function, which is resistant to dictionary attacks and rainbow table attacks. It is based on iteratively deriving HMAC many times with some padding. The PBKDF2 algorithm is described in the Internet standard RFC 2898 (PKCS #5).

PBKDF2 takes several input parameters and produces the derived key as output:

key = pbkdf2(password, salt, iterations-count, hash-function, derived-key-len)

Technically, the input data for PBKDF2 consists of:

The output data is the derived key of requested length (e.g. 256 bits).

PBKDF2 and Number of Iterations

PBKDF2 allows to configure the number of iterations and thus to configure the time required to derive the key.

  • Slower key derivation means high login time / slower decryption / etc. and higher resistance to password cracking attacks.

  • Faster key derivation means short login time / faster decryption / etc. and lower resistance to password cracking attacks.

  • PBKDF2 is not resistant to GPU attacks (parallel password cracking using video cards) and to ASIC attacks (specialized password cracking hardware). This is the main motivation behind more modern KDF functions.

PBKDF2 - Example

Try PBKDF2 key derivation online here: https://asecuritysite.com/encryption/PBKDF2z.

Try to increase the iterations count to see how this affects the speed of key derivation.

PBKDF2 Calculation in Python - Example

Now, we shall write some code in Python to derive a key from a password using the PBKDF2 algorithm.

Firstly, install the Python package backports.pbkdf2 using the command:

pip install backports.pbkdf2

Now, write the Python code to calculate PBKDF2:

import os, binasciifrom backports.pbkdf2 import pbkdf2_hmacsalt = binascii.unhexlify('aaef2d3f4d77ac66e9c5a6c3d8f921d1')passwd = "p@$Sw0rD~1".encode("utf8")key = pbkdf2_hmac("sha256", passwd, salt, 50000, 32)print("Derived key:", binascii.hexlify(key))

Run the above code example: https://repl.it/@nakov/PBKDF2-in-Python.

The PBKDF2 calculation function takes several input parameters: hash function for the HMAC, the password (bytes sequence), the salt (bytes sequence), iterations count and the output key length (number of bytes for the derived key).

The output from the above code execution is the following:

Derived key: b'52c5efa16e7022859051b1dec28bc65d9696a3005d0f97e506c42843bc3bdbc0'

Try to change the number of iterations and see whether and how the execution time changes.

When to Use PBKDF2?

Today PBKDF2 is considered old-fashioned and less secure than modern KDF functions, so it is recommended to use Bcrypt, Scrypt or Argon2 instead. We shall explain all these KDF functions in details later in this section.

PBKDF2 | Practical Cryptography for Developers (2024)
Top Articles
Dark Horse
Largest Market Makers - FasterCapital
Brady Hughes Justified
Z-Track Injection | Definition and Patient Education
Botanist Workbench Rs3
Mohawkind Docagent
Mustangps.instructure
How to Type German letters ä, ö, ü and the ß on your Keyboard
Visustella Battle Core
Toonily The Carry
Cincinnati Bearcats roll to 66-13 win over Eastern Kentucky in season-opener
Immediate Action Pathfinder
Cnnfn.com Markets
Job Shop Hearthside Schedule
Hca Florida Middleburg Emergency Reviews
Nebraska Furniture Tables
Grace Caroline Deepfake
What is Cyber Big Game Hunting? - CrowdStrike
A rough Sunday for some of the NFL's best teams in 2023 led to the three biggest upsets: Analysis - NFL
Buy PoE 2 Chaos Orbs - Cheap Orbs For Sale | Epiccarry
60 X 60 Christmas Tablecloths
Walmart stores in 6 states no longer provide single-use bags at checkout: Which states are next?
Water Days For Modesto Ca
Craigslist Free Stuff Merced Ca
E22 Ultipro Desktop Version
Divina Rapsing
Officialmilarosee
Jbf Wichita Falls
Huntersville Town Billboards
Indiana Wesleyan Transcripts
Https Paperlesspay Talx Com Boydgaming
Accuweather Minneapolis Radar
Pawn Shop Moline Il
Effingham Daily News Police Report
Franklin Villafuerte Osorio
Lil Durk's Brother DThang Killed in Harvey, Illinois, ME Confirms
Robot or human?
Devin Mansen Obituary
Best Weapons For Psyker Darktide
Pensacola 311 Citizen Support | City of Pensacola, Florida Official Website
Powerspec G512
Giantess Feet Deviantart
Scottsboro Daily Sentinel Obituaries
Rhode Island High School Sports News & Headlines| Providence Journal
Walmart Careers Stocker
Paperlessemployee/Dollartree
Stitch And Angel Tattoo Black And White
The Blackening Showtimes Near Ncg Cinema - Grand Blanc Trillium
Sleep Outfitters Springhurst
Wvu Workday
Jesus Calling Oct 6
Olay Holiday Gift Rebate.com
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 5276

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.