Permalink
Browse files

Use random_bytes() on PHP 7

  • Loading branch information...
1 parent 987aedb commit 94796a00e5a321f4b07c99bab67f86d92f0882fd @timoh6 committed Aug 10, 2016
Showing with 13 additions and 0 deletions.
  1. +13 −0 library/TCrypto/Crypto.php
View
13 library/TCrypto/Crypto.php
@@ -508,6 +508,19 @@ public static function getRandomBytes($count)
$bytes = '';
$hasBytes = false;
+ if (version_compare(PHP_VERSION, '7.0.0') >= 0 && function_exists('random_bytes'))
+ {
+ try
+ {
+ $bytes = \random_bytes($count);
+ $hasBytes = true;
+ }
+ catch (\Exception $e)
+ {
+ //
+ }
+ }
+
// Make sure PHP version is at least 5.3. We do this because
// mcrypt_create_iv() on older versions of PHP
// does not give "strong" random data on Windows systems.

0 comments on commit 94796a0

Please sign in to comment.