org\Crypt::createIV PHP Method

createIV() protected static method

随机生成指定长度的初始化向量
protected static createIV ( integer $size ) : string
$size integer 初始化向量长度
return string
    protected static function createIV($size)
    {
        if (function_exists('openssl_random_pseudo_bytes')) {
            $bytes = openssl_random_pseudo_bytes($size, $strong);
        }
        if (is_null($bytes) || false === $bytes || false === $strong) {
            $size *= 2;
            $pool = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $bytes = pack('H*', substr(str_shuffle(str_repeat($pool, $size)), 0, $size));
        }
        return $bytes;
    }