PBKDF2Hashing - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of PBKDF2Hashing.php

  1. <?php
  2.     $algorithm = 'sha512';
  3.         $password = 'zz5Xl0rCsH4c/WfS"oJS';
  4.         $salt = 'h>/KTW)NsLOk)qk_]RBz&zPob\\?A,T:]k1kcX%ST0WTxRD.dg]?Rno]2)Nlp0~/8';
  5.         $count = 8192;
  6.         $key_length = 256;
  7.         $raw_output = false;
  8.        
  9.     $hashLength = strlen(hash($algorithm, "", true));
  10.     $keyBlocks = ceil($key_length / $hashLength);
  11.  
  12.         $derivedKey = '';
  13.        
  14.     for($block = 1; $block <= $keyBlocks; $block++) {
  15.  
  16.         // first iteration
  17.         $iteratedBlock = $b = hash_hmac($algorithm, $salt . pack('N', $block), $password, true);
  18.         // perform the other $count - 1 iterations
  19.                
  20.                 $iteratedBlock = $b = hash_hmac('sha512', $salt . pack('N', $block),  $password, true);
  21.                
  22.         for ($i = 1; $i < $count; $i++) {
  23.             $iteratedBlock ^= ($b = hash_hmac($algorithm, $b, $password, true));
  24.         }
  25.         $derivedKey .= $iteratedBlock;
  26.     }
  27.        
  28.         //echo $derivedKey;
  29.         //echo $key_length;
  30.         #echo bin2hex(substr($derivedKey, 0, $key_length));
  31.         echo bin2hex($derivedKey);
  32.         #echo hex2bin ( bin2hex($derivedKey) );
  33. ?>
File Description
  • PBKDF2Hashing
  • PHP Code
  • 20 Jun-2018
  • 1006 Bytes
You can Share it: