Crypto.php 762 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace ACES\Common;
  3. use ACES\Common\Exception as Ex;
  4. final class Crypto
  5. {
  6. const CIPHER_METHOD_AES_128_CBC = 'aes-128-cbc';
  7. const CIPHER_BLOCK_SIZE = 16;
  8. const CIPHER_IV_SIZE = 16;
  9. const CIPHER_KEY_SIZE = 16;
  10. /**
  11. * Returns a random byte string of the specified length.
  12. *
  13. * @param int $octets
  14. *
  15. * @throws Ex\BrokenEnvironmentException
  16. *
  17. * @return string
  18. */
  19. public static function secureRandom($octets)
  20. {
  21. try {
  22. return \openssl_random_pseudo_bytes($octets);
  23. } catch (\Exception $ex) {
  24. throw new Ex\BrokenEnvironmentException(
  25. 'Your system does not have a secure random number generator.'
  26. );
  27. }
  28. }
  29. }