<?php

declare(strict_types=1);

namespace MyCustomizer\WooCommerce\Connector\Libs;

class MczrSecurity
{
    public function generateKey(int $bit_length = 128): string
    {
        $fp = @fopen('/dev/random', 'rb');
        if ($fp !== false) {
            $bytes = (int)(($bit_length + 7) / 8);
            $substrLength = (int)((($bit_length + 5) / 6) - 2);

            $key = substr(base64_encode(@fread($fp, $bytes)), 0, $substrLength);
            @fclose($fp);

            return $key;
        }

        return md5(microtime() . rand());
    }
}
