Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CryptoUtil.php « Util « PhpZip « src « zip « nelexa « vendor - github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7403c93de7347c5d7831b164ef83b494165deb74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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');
        }
    }
}