mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-18 14:43:09 +00:00
28 lines
583 B
PHP
28 lines
583 B
PHP
<?php
|
|
|
|
namespace RobThree\Auth\Providers\Rng;
|
|
|
|
class MCryptRNGProvider implements IRNGProvider
|
|
{
|
|
private $source;
|
|
|
|
public function __construct($source = MCRYPT_DEV_URANDOM)
|
|
{
|
|
$this->source = $source;
|
|
}
|
|
|
|
public function getRandomBytes($bytecount)
|
|
{
|
|
$result = @mcrypt_create_iv($bytecount, $this->source);
|
|
if ($result === false) {
|
|
throw new RNGException('mcrypt_create_iv returned an invalid value');
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function isCryptographicallySecure()
|
|
{
|
|
return true;
|
|
}
|
|
}
|