コード例 #1
0
 /**
  * {@inheritDoc}
  *
  * @deprecated This implementation is deprecated, as the mcrypt
  *   library is abandoned. Use {@link NativeRandomByteGenerator} instead.
  */
 public function generate($size)
 {
     trigger_error('This implementation is deprecated, as the mcrypt library is abandoned', E_USER_DEPRECATED);
     $generated = mcrypt_create_iv($size, $this->source);
     if (false === $generated || strlen($generated) !== $size) {
         throw CryptographicFailureException::forReasonCode(CryptographicFailureException::CODE_FOR_RANDOM_DATA_GENERATION_FAILURE);
     }
     return $generated;
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  *
  * @deprecated This implementation is deprecated, as it's been found
  *   to be insecure. Use {@link RandomByteGeneratorInterface} instead.
  */
 public function generate($size)
 {
     trigger_error('This implementation is deprecated, as it can be insecure in some circumstances', E_USER_DEPRECATED);
     $generated = openssl_random_pseudo_bytes($size, $strong);
     if (false === $generated || strlen($generated) !== $size || false === $strong) {
         throw CryptographicFailureException::forReasonCode(CryptographicFailureException::CODE_FOR_RANDOM_DATA_GENERATION_FAILURE);
     }
     return $generated;
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function generate($size)
 {
     try {
         $generated = random_bytes($size);
     } catch (Error $e) {
         // PHP 7+ will throw an `Error`. Catch here to make sure that we don't accidentally catch a polyfilled
         // `Error` from a polyfill library, such as https://github.com/paragonie/random_compat
         throw $e;
     } catch (Exception $e) {
         throw CryptographicFailureException::forReasonCode(CryptographicFailureException::CODE_FOR_RANDOM_DATA_GENERATION_FAILURE, $e);
     }
     return $generated;
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function encrypt($key, $data, $mode, $initialization_vector)
 {
     if (isset(self::$cipher_mode_map[$mode])) {
         $mode = self::$cipher_mode_map[$mode];
     } else {
         throw new InvalidArgumentException('Unknown cipher mode "' . $mode . '"');
     }
     $key = $this->processKey($key);
     $encrypted = mcrypt_encrypt(MCRYPT_DES, $key, $data, $mode, $initialization_vector);
     if (false === $encrypted) {
         throw CryptographicFailureException::forReasonCode(CryptographicFailureException::CODE_FOR_ENCRYPTION_FAILURE);
     }
     return $encrypted;
 }