OpenSSLRNGProvider.php 793 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace RobThree\Auth\Providers\Rng;
  3. class OpenSSLRNGProvider implements IRNGProvider
  4. {
  5. private $requirestrong;
  6. function __construct($requirestrong = true) {
  7. $this->requirestrong = $requirestrong;
  8. }
  9. public function getRandomBytes($bytecount) {
  10. $result = openssl_random_pseudo_bytes($bytecount, $crypto_strong);
  11. if ($this->requirestrong && ($crypto_strong === false))
  12. throw new \RNGException('openssl_random_pseudo_bytes returned non-cryptographically strong value');
  13. if ($result === false)
  14. throw new \RNGException('openssl_random_pseudo_bytes returned an invalid value');
  15. return $result;
  16. }
  17. public function isCryptographicallySecure() {
  18. return $this->requirestrong;
  19. }
  20. }