length = $length; } /** * @throws \Mollie\Api\Exceptions\IncompatiblePlatform * @return string */ public function generate() { $length = $this->length; $string = ''; while (($len = \strlen($string)) < $length) { $size = $length - $len; try { $bytes = \random_bytes($size); } catch (\Exception $e) { throw new \Mollie\Api\Exceptions\IncompatiblePlatform('PHP function random_bytes missing. Consider overriding the DefaultIdempotencyKeyGenerator with your own.', \Mollie\Api\Exceptions\IncompatiblePlatform::INCOMPATIBLE_RANDOM_BYTES_FUNCTION); } $string .= \substr(\str_replace(['/', '+', '='], '', \base64_encode($bytes)), 0, $size); } return $string; } }