MCryptRNGProvider.php 564 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace RobThree\Auth\Providers\Rng;
  3. class MCryptRNGProvider implements IRNGProvider
  4. {
  5. private $source;
  6. function __construct($source = MCRYPT_DEV_URANDOM) {
  7. $this->source = $source;
  8. }
  9. public function getRandomBytes($bytecount) {
  10. $result = @mcrypt_create_iv($bytecount, $this->source);
  11. if ($result === false)
  12. throw new \RNGException('mcrypt_create_iv returned an invalid value');
  13. return $result;
  14. }
  15. public function isCryptographicallySecure() {
  16. return true;
  17. }
  18. }