3

I have encrypted the string using PHP hash_pbkdf2 function. Please review the below code:

$password = "password";
$iterations = 10000;
$salt = 1111;

$hash = hash_pbkdf2("sha256", $password, $salt, $iterations, 20);


The result of hash value "61ea90120ac05230465c"

Everything working fine in encryption.

Please let me know how to decrepit the value "61ea90120ac05230465c" and get the result of "password"

Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206
Kanewilliam
  • 199
  • 2
  • 18
  • 4
    [hashing != encrypting](https://www.securityinnovationeurope.com/blog/page/whats-the-difference-between-hashing-and-encrypting) – Jeff Sep 17 '18 at 11:21
  • 2
    hash function can't decrypt. this is one way function. if you need encrypt and decrypt then used A3 (encryption cipher ) but this is bad way for password – Bilal Ahmed Sep 17 '18 at 11:21
  • if you think one could easily 'decrypt' this hash - why would you then wanna use it? – Jeff Sep 17 '18 at 11:26

1 Answers1

2

Short answer: You can't. Might I recommend this approach instead?


Longer answer (excerpted from this article which explains cryptography terms to developers):

Many developers think passwords should be encrypted, but this is false. Passwords should be hashed, not encrypted. Furthermore, don't confuse password hashing algorithms with simple cryptographic hash functions. They're not the same thing:

Table comparing cryptographic hashes versus password hashes

Unlike cryptographic hashes, password hashes require more than one input parameter. But unlike encryption algorithms, password hashes are one-way deterministic trap door calculations. Also unlike secret-key encryption, the salt does not need to remain secret; it merely needs to be unique per user. The purpose of a unique salt per user is to thwart pre-computation and to make brute-force guessing passwords from a list of hashes more expensive.

The function hash_pbkdf2() is a type of hash function, so you cannot decrypt it.

Furthermore, the name of the algorithm it uses is PBKDF2, or Password-Based Key Derivation Function #2. It was designed to turn a password (a low-entropy human-sourced and human-memorizable input) into a secure cryptography key. The way it does this under the hood led a lot of people to use PBKDF2 as a password hash.

While there are some key differences between KDFs and password hashing algorithms, for the sake of this answer, they're essentially the same type of algorithm.

So the answer to "how to [decrypt] this PBKDF2 output?" is: You can't.

Hash functions are one-way. There are infinite inputs that can produce any given hash output, but because the output keyspace is so vast with secure hash functions, it's computationally infeasible to generate a collision.

This is also true of password hashing functions (and key derivation functions), except exacerbated by:

  1. Salting
  2. Iterated hashing
  3. (In some cases) Memory-hard algorithm designs that make it difficult to perform a brute force attack by using parallel processing.

The solution is to use the right tool for the job. And if you don't know what that is, start here so you understand the terms, then see this answer for example code.

Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206