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 = 2048; if( !function_exists("hash_pbkdf2") ){ $hash = pbkdf2( "whirlpool", $plain_text, $salt[0], $iterations, 512, true ); $hash = pbkdf2( "sha512", $hash, $salt[1], $iterations, 512 ); } else { $hash = hash_pbkdf2( "whirlpool", $plain_text, $salt[0], $iterations, 512, true ); $hash = 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"; $time = time(); $result = get_hash( $plain_text, $salt ); echo $result; echo "\ntime: ". ( time() - $time ); } test(); ?>
based on BjHli
Output for 5.5.0 - 5.5.15, 5.5.18 - 5.5.28, 5.5.30, 5.5.32 - 5.5.33, 5.5.35 - 5.6.9, 5.6.11 - 7.2.0
start 4804062a0e41778c6352d63b29e2cf361cd519091ab8ee7b207e6db2fc5d80e24e882a81ef0ee224828cef8b067a02284bb56d809f7dd44d7b1f9e254cb4dd39cc6cf8a76af19f9a754ceae663723fb2ffc2f7168f9a9189dbd90d91ac1b8e26bbe332abb3a49759806bd0e6c8c3f15deec84d6f8ce9d64d64cc2d65b9e4770062251ff78f034853ecb66ac8e9543a8e65e80835df6f854355b5e0d8fdafb2b7fe53376a2618e7d37fdd4ea80736abc966365a3247b2ad0f4c73b12b0b1296a5391a5d3a5e867c05ea7063a5c15b3357c1088eb596ca7174e886fead5fd691318b6190a46d551dc05a0925b22220068214ca4b98941f0c834e08b702431b5405 time: 0
Output for 5.5.16, 5.5.29, 5.5.31, 5.5.34, 5.6.10
start 4804062a0e41778c6352d63b29e2cf361cd519091ab8ee7b207e6db2fc5d80e24e882a81ef0ee224828cef8b067a02284bb56d809f7dd44d7b1f9e254cb4dd39cc6cf8a76af19f9a754ceae663723fb2ffc2f7168f9a9189dbd90d91ac1b8e26bbe332abb3a49759806bd0e6c8c3f15deec84d6f8ce9d64d64cc2d65b9e4770062251ff78f034853ecb66ac8e9543a8e65e80835df6f854355b5e0d8fdafb2b7fe53376a2618e7d37fdd4ea80736abc966365a3247b2ad0f4c73b12b0b1296a5391a5d3a5e867c05ea7063a5c15b3357c1088eb596ca7174e886fead5fd691318b6190a46d551dc05a0925b22220068214ca4b98941f0c834e08b702431b5405 time: 1
Output for 5.4.0, 5.4.2 - 5.4.4, 5.4.6 - 5.4.11, 5.4.13 - 5.4.17, 5.4.19, 5.4.21 - 5.4.23, 5.4.25, 5.4.27, 5.4.29 - 5.4.32, 5.4.35 - 5.4.39, 5.4.41 - 5.4.43, 5.4.45
start 4804062a0e41778c6352d63b29e2cf361cd519091ab8ee7b207e6db2fc5d80e24e882a81ef0ee224828cef8b067a02284bb56d809f7dd44d7b1f9e254cb4dd39cc6cf8a76af19f9a754ceae663723fb2ffc2f7168f9a9189dbd90d91ac1b8e26bbe332abb3a49759806bd0e6c8c3f15deec84d6f8ce9d64d64cc2d65b9e4770062251ff78f034853ecb66ac8e9543a8e65e80835df6f854355b5e0d8fdafb2b7fe53376a2618e7d37fdd4ea80736abc966365a3247b2ad0f4c73b12b0b1296a5391a5d3a5e867c05ea7063a5c15b3357c1088eb596ca7174e886fead5fd691318b6190a46d551dc05a0925b22220068214ca4b98941f0c834e08b702431b54058ce8f76c4ec9cd9d7fd6cf66363cbae818060a39a2ff8ec17b8ff229452b57c46d54abf46790d6cf4e5115db0f1cadeb3367ea42379c9b2bcc20da59a10ff8f853eb116e71fc9a4eb521400a5c4b2f380a03748026b68ae9de938f8aff040834d03696a715b4f32adfa03bc5b18e56c367f6222cd86a5c2cc38a9d398360976335312abab09b0dd74fa68636d2688d479ede5a41cb46f3894c4347317e0a0c413fd8a1039aa088cd293af1c7ca47946d6438b0199514b28345cff0af847d6aaa1316114f2641a94e4c2509b52fca1e81b34bde0844d7a762268eedc611399c0ce1b352bd9ccf2037b74c81f4e688a97b521b259776ff64a368c2d8b578243b0c time: 0
Output for 5.4.1, 5.4.5, 5.4.12, 5.4.18, 5.4.20, 5.4.24, 5.4.26, 5.4.28, 5.4.34, 5.4.40, 5.4.44
start 4804062a0e41778c6352d63b29e2cf361cd519091ab8ee7b207e6db2fc5d80e24e882a81ef0ee224828cef8b067a02284bb56d809f7dd44d7b1f9e254cb4dd39cc6cf8a76af19f9a754ceae663723fb2ffc2f7168f9a9189dbd90d91ac1b8e26bbe332abb3a49759806bd0e6c8c3f15deec84d6f8ce9d64d64cc2d65b9e4770062251ff78f034853ecb66ac8e9543a8e65e80835df6f854355b5e0d8fdafb2b7fe53376a2618e7d37fdd4ea80736abc966365a3247b2ad0f4c73b12b0b1296a5391a5d3a5e867c05ea7063a5c15b3357c1088eb596ca7174e886fead5fd691318b6190a46d551dc05a0925b22220068214ca4b98941f0c834e08b702431b54058ce8f76c4ec9cd9d7fd6cf66363cbae818060a39a2ff8ec17b8ff229452b57c46d54abf46790d6cf4e5115db0f1cadeb3367ea42379c9b2bcc20da59a10ff8f853eb116e71fc9a4eb521400a5c4b2f380a03748026b68ae9de938f8aff040834d03696a715b4f32adfa03bc5b18e56c367f6222cd86a5c2cc38a9d398360976335312abab09b0dd74fa68636d2688d479ede5a41cb46f3894c4347317e0a0c413fd8a1039aa088cd293af1c7ca47946d6438b0199514b28345cff0af847d6aaa1316114f2641a94e4c2509b52fca1e81b34bde0844d7a762268eedc611399c0ce1b352bd9ccf2037b74c81f4e688a97b521b259776ff64a368c2d8b578243b0c time: 1