public static function generateCryptoKey($length)
    {
        // PHP>=7.0
        if (function_exists('random_bytes')) {
            return random_bytes($length);
        }
        
        $buf = openssl_random_pseudo_bytes($length, $secure);

        if ($buf !== false) {
            return $buf;
        }

        throw new \Exception('PRNG failure');
    }