diff options
Diffstat (limited to 'vendor/nelexa/zip/src/PhpZip/Util/CryptoUtil.php')
-rw-r--r-- | vendor/nelexa/zip/src/PhpZip/Util/CryptoUtil.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/nelexa/zip/src/PhpZip/Util/CryptoUtil.php b/vendor/nelexa/zip/src/PhpZip/Util/CryptoUtil.php new file mode 100644 index 0000000..7403c93 --- /dev/null +++ b/vendor/nelexa/zip/src/PhpZip/Util/CryptoUtil.php @@ -0,0 +1,33 @@ +<?php + +namespace PhpZip\Util; + +use PhpZip\Exception\RuntimeException; + +/** + * Crypto Utils + */ +class CryptoUtil +{ + + /** + * Returns random bytes. + * + * @param int $length + * @return string + * @throws RuntimeException + */ + final public static function randomBytes($length) + { + $length = (int)$length; + if (function_exists('random_bytes')) { + return random_bytes($length); + } elseif (function_exists('openssl_random_pseudo_bytes')) { + return openssl_random_pseudo_bytes($length); + } elseif (function_exists('mcrypt_create_iv')) { + return mcrypt_create_iv($length); + } else { + throw new RuntimeException('Extension openssl or mcrypt not loaded'); + } + } +} |