3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @file * Contains \Drupal\Component\Utility\Crypt. */ namespace Drupal\Component\Utility { /** * Utility class for cryptographically-secure string handling routines. */ class Crypt { /** * Returns a string of highly randomized bytes (over the full 8-bit range). * * This function is better than simply calling mt_rand() or any other built-in * PHP function because it can return a long string of bytes (compared to < 4 * bytes normally from mt_rand()) and uses the best available pseudo-random * source. * * @param int $count * The number of characters (bytes) to return in the string. * * @return string * A randomly generated string. */ public static function randomBytes($count) { static $random_state, $bytes; // Initialize on the first call. The contents of $_SERVER includes a mix of // user-specific and system information that varies a little with each page. // Further initialize with the somewhat random PHP process ID. if (!isset($random_state)) { $random_state = print_r($_SERVER, TRUE) . getmypid(); $bytes = ''; } if (strlen($bytes) < $count) { // /dev/urandom is available on many *nix systems and is considered the // best commonly available pseudo-random source. if ($fh = @fopen('/dev/urandom', 'rb')) { // PHP only performs buffered reads, so in reality it will always read // at least 4096 bytes. Thus, it costs nothing extra to read and store // that much so as to speed any additional invocations. $bytes .= fread($fh, max(4096, $count)); fclose($fh); } // openssl_random_pseudo_bytes() will find entropy in a system-dependent // way. elseif (function_exists('openssl_random_pseudo_bytes')) { $bytes .= openssl_random_pseudo_bytes($count - strlen($bytes)); } // If /dev/urandom is not available or returns no bytes, this loop will // generate a good set of pseudo-random bytes on any system. // Note that it may be important that our $random_state is passed // through hash() prior to being rolled into $output, that the two hash() // invocations are different, and that the extra input into the first one - // the microtime() - is prepended rather than appended. This is to avoid // directly leaking $random_state via the $output stream, which could // allow for trivial prediction of further "random" numbers. while (strlen($bytes) < $count) { $random_state = hash('sha256', microtime() . mt_rand() . $random_state); $bytes .= hash('sha256', mt_rand() . $random_state, TRUE); } } $output = substr($bytes, 0, $count); $bytes = substr($bytes, $count); return $output; } /** * Calculates a base-64 encoded, URL-safe sha-256 hmac. * * @param mixed $data * Scalar value to be validated with the hmac. * @param mixed $key * A secret key, this can be any scalar value. * * @return string * A base-64 encoded sha-256 hmac, with + replaced with -, / with _ and * any = padding characters removed. */ public static function hmacBase64($data, $key) { // $data and $key being strings here is necessary to avoid empty string // results of the hash function if they are not scalar values. As this // function is used in security-critical contexts like token validation it // is important that it never returns an empty string. if (!is_scalar($data) || !is_scalar($key)) { throw new \InvalidArgumentException('Both parameters passed to \Drupal\Component\Utility\Crypt::hmacBase64 must be scalar values.'); } $hmac = base64_encode(hash_hmac('sha256', $data, $key, TRUE)); // Modify the hmac so it's safe to use in URLs. return strtr($hmac, array('+' => '-', '/' => '_', '=' => '')); } /** * Calculates a base-64 encoded, URL-safe sha-256 hash. * * @param string $data * String to be hashed. * * @return string * A base-64 encoded sha-256 hash, with + replaced with -, / with _ and * any = padding characters removed. */ public static function hashBase64($data) { $hash = base64_encode(hash('sha256', $data, TRUE)); // Modify the hash so it's safe to use in URLs. return strtr($hash, array('+' => '-', '/' => '_', '=' => '')); } /** * Generates a random, base-64 encoded, URL-safe, sha-256 hashed string. * * @param int $count * The number of characters (bytes) of the string to be hashed. * * @return string * A base-64 encoded sha-256 hash, with + replaced with -, / with _ and * any = padding characters removed. * * @see \Drupal\Component\Utility\Crypt::randomBytes() * @see \Drupal\Component\Utility\Crypt::hashBase64() */ public static function randomStringHashed($count) { return static::hashBase64(static::randomBytes($count)); } } } namespace { var_dump(\Drupal\Component\Utility\Crypt::randomBytes(8)); }
Output for 8.0.11
string(8) "����)�"
Output for 8.0.10
string(8) " Sp誟�g"
Output for 8.0.9
string(8) "H�kC�y`"
Output for 8.0.8
string(8) "��'KX�_~"
Output for 8.0.7
string(8) "�@�#o��"
Output for 8.0.6
string(8) "��Vp 6�"
Output for 8.0.5
string(8) "�>��N�"
Output for 8.0.3
string(8) "m�:�w�"
Output for 8.0.2
string(8) ".`�$��m"
Output for 8.0.1
string(8) "L���<Va"
Output for 8.0.0
string(8) "���b��"
Output for 7.4.24
string(8) "������"
Output for 7.4.23
string(8) "��Kg� "
Output for 7.4.22
string(8) "F�ġ���"
Output for 7.4.21
string(8) "��B ��"
Output for 7.4.20
string(8) "ubYܟ�~"
Output for 7.4.19
string(8) "�������"
Output for 7.4.16
string(8) "Z�T�~��`"
Output for 7.4.15
string(8) "�ٙ�f@"
Output for 7.4.14
string(8) "�֭7xk@"
Output for 7.4.13
string(8) "���P��"
Output for 7.4.12
string(8) "��܂j��"
Output for 7.4.11
string(8) " !���K�"
Output for 7.4.10
string(8) "ɓ03JF�"
Output for 7.4.9
string(8) "|�'��l��"
Output for 7.4.8
string(8) "´�,��ܐ"
Output for 7.4.7
string(8) "�1'D���"
Output for 7.4.6
string(8) "ZI�W�i9"
Output for 7.4.5
string(8) "7I�O��8x"
Output for 7.4.4
string(8) "siA���`"
Output for 7.4.3
string(8) "ӓ� </�"
Output for 7.4.0
string(8) "��)�ع"
Output for 7.3.30
string(8) "�6�9�]["
Output for 7.3.29
string(8) "�L= �4/"
Output for 7.3.28
string(8) "��kQ��e*"
Output for 7.3.27
string(8) "�Ig)�G��"
Output for 7.3.26
string(8) "�<͜s��"
Output for 7.3.25
string(8) "� =<"
Output for 7.3.24
string(8) "�>N5 ��4"
Output for 7.3.23
string(8) "t�m��?"
Output for 7.3.21
string(8) "-� �L2"
Output for 7.3.20
string(8) "Y<�J���"
Output for 7.3.19
string(8) "Φ <��"
Output for 7.3.18
string(8) "$�9��"
Output for 7.3.17
string(8) "W��lm;�"
Output for 7.3.16
string(8) "�o'2䄰"
Output for 7.3.12
string(8) "�d��.�"
Output for 7.3.1
string(8) "`+�Y��"
Output for 7.3.0
string(8) "y����d�"
Output for 7.2.33
string(8) "D��+�i�"
Output for 7.2.32
string(8) "��{�^�z�"
Output for 7.2.31
string(8) "�>~ͪ\�j"
Output for 7.2.30
string(8) "d� \���"
Output for 7.2.29
string(8) "��&<�,�"
Output for 7.2.13
string(8) "�d�е�m|"
Output for 7.2.12
string(8) "���F�*�"
Output for 7.2.11
string(8) "<��j"���"
Output for 7.2.10
string(8) "�Z;��d6"
Output for 7.2.9
string(8) "�WX��Vl"
Output for 7.2.8
string(8) "Ѧ���F"
Output for 7.2.7
string(8) "h�~c�\�"
Output for 7.2.6
string(8) "��O�u"
Output for 7.2.5
string(8) "S� W��Ib"
Output for 7.2.4
string(8) "k�r�Ҁ��"
Output for 7.2.3
string(8) "�T�F��"
Output for 7.2.2
string(8) "6��3�b"
Output for 7.2.1
string(8) "����y@�"
Output for 7.2.0
string(8) ";NY�["
Output for 7.1.25
string(8) "��~Sn� �"
Output for 7.1.20
string(8) ")0�;� �"
Output for 7.1.10
string(8) "�� � �o"
Output for 7.1.7
string(8) "Pt��/H"
Output for 7.1.6
string(8) "R~��8"
Output for 7.1.5
string(8) "jF��K��"
Output for 7.1.0
string(8) "`���Z�d�"
Output for 7.0.20
string(8) "���7�$�G"
Output for 7.0.14
string(8) "K9]��|"
Output for 7.0.10
string(8) "פ�AS�6"
Output for 7.0.9
string(8) "-��Ii�B"
Output for 7.0.8
string(8) "���V;7"
Output for 7.0.7
string(8) "sV!>�;Z"
Output for 7.0.6
string(8) "M���ɳ@"
Output for 7.0.5
string(8) "67kL+"
Output for 7.0.4
string(8) ")�rjւ�"
Output for 7.0.3
string(8) "�c��*j�"
Output for 7.0.2
string(8) "6\Gڎ��0"
Output for 7.0.1
string(8) " ��򯿌�"
Output for 7.0.0
string(8) "��FB"
Output for 5.6.28
string(8) "� �'� �"
Output for 5.6.25
string(8) "2����C&"
Output for 5.6.24
string(8) "��g 7�"
Output for 5.6.23
string(8) "X� �M��"
Output for 5.6.22
string(8) "�0.䠭�"
Output for 5.6.21
string(8) "��(B�"
Output for 5.6.20
string(8) ""-�Y��9,"
Output for 5.6.19
string(8) "; �(CŠ�"
Output for 5.6.18
string(8) "�/U�����"
Output for 5.6.17
string(8) "�+p�44{�"
Output for 5.6.16
string(8) "�B" "
Output for 5.6.15
string(8) "@,K� ��"
Output for 5.6.14
string(8) "��m漠�"
Output for 5.6.13
string(8) "�s5���"
Output for 5.6.12
string(8) "~�9;�8"
Output for 5.6.11
string(8) "�p���"
Output for 5.6.10
string(8) "��|�fv�z"
Output for 5.6.9
string(8) "7�me<���"
Output for 5.6.8
string(8) "�Ш�̾�."
Output for 5.6.7
string(8) "����@O "
Output for 5.6.6
string(8) "�� �"5�"
Output for 5.6.5
string(8) "�dݾm̀�"
Output for 5.6.4
string(8) "P�f�<]��"
Output for 5.6.3
string(8) "Ϸb�%�9M"
Output for 5.6.2
string(8) "��?����6"
Output for 5.6.1
string(8) "�O?I� E�"
Output for 5.6.0
string(8) "��q^׈<�"
Output for 5.5.38
string(8) "`أ�c( "
Output for 5.5.37
string(8) "bƜ0� "
Output for 5.5.36
string(8) "%�"� �"
Output for 5.5.35
string(8) "���M"
Output for 5.5.34
string(8) "����c���"
Output for 5.5.33
string(8) "�����>�"
Output for 5.5.32
string(8) "ڣt���"
Output for 5.5.31
string(8) "�P@B^�|#"
Output for 5.5.30
string(8) "� T.L�"
Output for 5.5.29
string(8) "�`H���"
Output for 5.5.28
string(8) "�r��� "
Output for 5.5.27
string(8) "��o�Z"
Output for 5.5.26
string(8) "���5�O"
Output for 5.5.25
string(8) "�3�vR4{"
Output for 5.5.24
string(8) "�J���Z�"
Output for 5.5.23
string(8) "���8d�|"
Output for 5.5.22
string(8) "��Ӯ�P"
Output for 5.5.21
string(8) "O���{g"
Output for 5.5.20
string(8) "l���.r"
Output for 5.5.19
string(8) " �e�q��,"
Output for 5.5.18
string(8) "#ND٨� '"
Output for 5.5.16
string(8) "nd�G=�"
Output for 5.5.15
string(8) "<Ȓ�솸"
Output for 5.5.14
string(8) "�F̈́���["
Output for 5.5.13
string(8) "�(Wc"C�"
Output for 5.5.12
string(8) "�E��RK�"
Output for 5.5.11
string(8) "�^�}n"
Output for 5.5.10
string(8) "A`�Ŵ.�"
Output for 5.5.9
string(8) "4U�k��q�"
Output for 5.5.8
string(8) "-D��"
Output for 5.5.7
string(8) "��G8���"
Output for 5.5.6
string(8) "�y����"
Output for 5.5.5
string(8) "i�8ͨ_"
Output for 5.5.4
string(8) "NQ���4J�"
Output for 5.5.3
string(8) "R�~]���2"
Output for 5.5.2
string(8) "�%R+V;"
Output for 5.5.1
string(8) "H��fܱAE"
Output for 5.5.0
string(8) "$D��p�{�"
Output for 5.4.45
string(8) "��TNw�E"
Output for 5.4.44
string(8) "��.�ۙ�j"
Output for 5.4.43
string(8) "1š0}"�"
Output for 5.4.42
string(8) "�ҭӔa"
Output for 5.4.41
string(8) "O� �6�N�"
Output for 5.4.40
string(8) "�WRud^�"
Output for 5.4.39
string(8) "��_|� Ku"
Output for 5.4.38
string(8) "�Ҡ}�1"
Output for 5.4.37
string(8) "�5o��;��"
Output for 5.4.36
string(8) "{�R�ۭ�f"
Output for 5.4.35
string(8) "�����n�m"
Output for 5.4.34
string(8) "�� �S�e"
Output for 5.4.32
string(8) "��Ec�V�s"
Output for 5.4.31
string(8) "��L��$�"
Output for 5.4.30
string(8) ""��A�F�"
Output for 5.4.29
string(8) "�Ou�X릖"
Output for 5.4.28
string(8) ",MHX��"
Output for 5.4.27
string(8) "%��]��"
Output for 5.4.26
string(8) "z$!(�]]3"
Output for 5.4.25
string(8) "��Ɏm(�"
Output for 5.4.24
string(8) "ѿ�@�oN�"
Output for 5.4.23
string(8) "��PjZ�"
Output for 5.4.22
string(8) "��Bt���"
Output for 5.4.21
string(8) "/f��T�/"
Output for 5.4.20
string(8) "<��;y���"
Output for 5.4.19
string(8) "����:u"
Output for 5.4.18
string(8) "Ou}� �~P"
Output for 5.4.17
string(8) "�-���kK�"
Output for 5.4.16
string(8) "�)_;�� "
Output for 5.4.15
string(8) "�|�Mkg�C"
Output for 5.4.14
string(8) "��ܧ��("
Output for 5.4.13
string(8) "�9W�iP$�"
Output for 5.4.12
string(8) "�gL{��*"
Output for 5.4.11
string(8) "��^�%�e"
Output for 5.4.10
string(8) "�7`}rC�@"
Output for 5.4.9
string(8) "ݖ�vu� "
Output for 5.4.8
string(8) "ﶶ�7W<"
Output for 5.4.7
string(8) "����'("
Output for 5.4.6
string(8) "�O�Ś��/"
Output for 5.4.5
string(8) "���UĖ�"
Output for 5.4.4
string(8) "unrW���"
Output for 5.4.3
string(8) "z +�D�X"
Output for 5.4.2
string(8) "�[s�? �E"
Output for 5.4.1
string(8) "���sg�#"
Output for 5.4.0
string(8) "��u���o�"
Output for 5.3.29
string(8) "&��_ʭ "
Output for 5.3.28
string(8) "7���;�T�"
Output for 5.3.27
string(8) "o�ͭ0X�"
Output for 5.3.26
string(8) "/f,�uE�"
Output for 5.3.25
string(8) "���� ��"
Output for 5.3.24
string(8) "{�w�d"
Output for 5.3.23
string(8) "C ��-/�"
Output for 5.3.22
string(8) "1�n���M"
Output for 5.3.21
string(8) "ɨ9E��E�"
Output for 5.3.20
string(8) "L�w�s�"
Output for 5.3.19
string(8) "S�Q�v"
Output for 5.3.18
string(8) "�) ��9U�"
Output for 5.3.17
string(8) "��S󕉻"
Output for 5.3.16
string(8) ",��;+}"
Output for 5.3.15
string(8) "�)�]b"
Output for 5.3.14
string(8) "-� ����"
Output for 5.3.13
string(8) " �#��d�*"
Output for 5.3.12
string(8) "���1�i �"
Output for 5.3.11
string(8) "��޳�T"
Output for 5.3.10
string(8) "��:�7�k�"
Output for 5.3.9
string(8) "m�,G��6"
Output for 5.3.8
string(8) "/��ld"
Output for 5.3.7
string(8) "�c�d"
Output for 5.3.6
string(8) "�M���s0"
Output for 5.3.5
string(8) "��Z�"
Output for 5.3.4
string(8) "�I��S���"
Output for 5.3.3
string(8) "9�3B�g�^"
Output for 5.3.2
string(8) "�ד�]�9"
Output for 5.3.1
string(8) "���J;��"
Output for 5.3.0
string(8) " AY��W"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/qDh1U on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/qDh1U on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qDh1U on line 8
Process exited with code 255.

preferences:
238.68 ms | 401 KiB | 286 Q