3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function pbkdf2( $algorithm = 'sha512', $password, $salt, $count = 2048, $key_length = 512, $raw_output = false ){ if($count <= 0 || $key_length <= 0) { $count = 2048; $key_length = 512; } $hash_length = strlen(hash($algorithm, "", true)); $block_count = ceil($key_length / $hash_length); $output = ""; for($i = 1; $i <= $block_count; $i++) { $last = $salt . pack("N", $i); $last = $xorsum = hash_hmac($algorithm, $last, $password, true); for ($j = 1; $j < $count; $j++) { $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true)); } $output .= $xorsum; } if($raw_output) { return substr($output, 0, $key_length); } else { return bin2hex(substr($output, 0, $key_length)); } } function generate_salt(){ $random = file_get_contents( '/dev/urandom', false, null, 0, 256 ); return bin2hex( $random ); } function get_hash( $plain_text, $salt ){ if( !isset($plain_text) || !isset($salt) ){ return false; } if( gettype($salt) == "string" ){ $salt = array( $salt, $salt ); } $iterations = 1024; $hash = pbkdf2( "whirlpool", $plain_text, $salt[0], $iterations, 512, true ); $hash = pbkdf2( "sha512", $hash, $salt[1], $iterations, 512 ); return $hash; } function test(){ $salt = array( 0 => generate_salt(), 1 => generate_salt() ); $salt = array( 0 => '5162e9d43703517e8efa9c0ff835e6d49914e60ae567574466e21bdbb6d6e647d58e468c3b5ff1b4b5bf667ce7d9896d0a8535bb9e862c65f998ba45fafa5fee1eef524873f3daf5405a36a471dc87803ac25df9d05463649e80941982c97315fb94b0d8d812420e1433fa45b75cbfba70723d5ad7fefe10a4e4d6e4759bacaa93903947e1f9157b204fbd17c489cc5edeb02f35301b45a4e3f0097aadf74e7bbdc25050c685e236fd90125e236e2eb349ec1bf2a7a33f3e6e1555b8658c0fcb155220b14cf03f420a7fda1012b089238c2c6226bf0d5c38742df8853caccd6f23baa0b2430731d4ba9c52d5b1d7e07622524969399971ad42a4af1195b14e7b', 1 => '81c36d5f5612aeae6b5d5595f0ed1541f6f732f1512695baceb514e1964f9a0551d902945df52c81a77f3b66936040be1eb723e571e5d1de7769fe016ccfa7b9468e1d912b17d608f052a3ae834254445be575c47f75f88464116698dba29694e5da8082c1e97430ab46cf7d5be5d0e2c4f94db93eb8c7bfdd5bb84d68d4685a31f6fb06e2408a268a651395b9faef509acbfdbb9d32fd0ffe5b8b7f7f71e72c825fe2e516e3be082041807978bc17a48f2ed53ed00a8533cbaa90b49b6ebda6028406a1845ada1ac77ca7433ee27449913afd82726d47c96237b9f5059404033e1bc62a60ffcd9d174f6ca49b6b07a0ae3042bc1ba06ad56e85466cf4cc6025' ); $plain_text = "mysupersecurepassword"; echo "start\n"; $result = get_hash( $plain_text, $salt ); echo $result; } test(); ?>
based on euTZF
Output for 5.3.19 - 7.2.0
start c08c226b312bacf41a72ba6bbdf59eaf5cb30053c252dbcf8671bef8521b12467771638684c993d749bb59085c4348a3c70d32e5e8bab40a2b7d05766034365ec9e8fd40430ff39ee06cc0285eda6d23603ecf6d013747fffa2a0e2dba07c1b16806c685b779f432e403f50cec08a7da920338c171136f83584c54e5dbd6cda55f32feeaf01be7f3420950f9c000ab0a59cd28d0c0fe1ec9dde06432c531755c61a320003bd7a7735c1a4a0a7baf7a796701b9d844cac22d6e1641bd3d83eb01485af5b53db57e5d54e5592d6336d600e441bbbe21d7cf9c66cd2ef6c2f1f06a9a4e9f95c1ca9862b25549318128c26f45375fada5ce7ae6ca63e56d2ea8c944eeca578b3a4d7b899e7f4aa1022887a363528459da318c9717f9fa205d34dddcbe76654f6d79977a56d455191877f5ea0bd422e12b0d364199757f79da536e0612064fcc72ca0a0d95f82ed700353a5e9fb4130477cccc35ac635e491cd53046fd445885358efc11c039b50d35f1a08fc3216a8d69c0bb4bcca9045e43f03955900ff26cfbfdd29e2a0bb433bc3626b4de78a063d97aa1e6fa5854a258bf4116e667e36751760ec6f7649a73059dfb955ba9877fec0d4d48e8af7980e847d29ca52e05a8e904687ee591eaa69da01e17a9f8a0a968d19811051fdb97522247f8c325678373031dc8b34222eea75463246025946dada354b1a3e7e4882a4f2cd2