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.     mb_internal_encoding("UTF-8");
  3.     
  4.     $algorithm = 'sha512';
  5.         $password = 'Oyx5UWZ$C\=;Cca!a@T#';
  6.         $salt = 'Cd(G;1V(FZ4BK}~<v;dVNN8j8A}GAwBMiWHgo2l.5uA+)6JR6P!qj?Ux4.YU>nXw';
  7.         $count = 8192;
  8.         $key_length = 256;
  9.         $raw_output = false;
  10.        
  11.     $hashLength = strlen(hash($algorithm, "", true));
  12.     $keyBlocks = ceil($key_length / $hashLength);
  13.  
  14.         $derivedKey = '';
  15.        
  16.     for($block = 1; $block <= $keyBlocks; $block++) {
  17.  
  18.         // first iteration
  19.         $iteratedBlock = $b = hash_hmac($algorithm, $salt . pack('N', $block), $password, true);
  20.         // perform the other $count - 1 iterations
  21.                
  22.                 $iteratedBlock = $b = hash_hmac('sha512', $salt . pack('N', $block),  $password, true);
  23.                
  24.         for ($i = 1; $i < $count; $i++) {
  25.             $iteratedBlock ^= ($b = hash_hmac($algorithm, $b, $password, true));
  26.         }
  27.         $derivedKey .= $iteratedBlock;
  28.     }
  29.        
  30.         echo "Hex: " . bin2hex($derivedKey) . "\n";
  31.         echo "\n";
  32.     echo "Base64: " . base64_encode($derivedKey) . "\n";
  33.  
  34. ?>
File Description
  • PBKDF2Hashing
  • PHP Code
  • 20 Jun-2018
  • 996 Bytes
You can Share it: