Exemple #1
0
 /**
  * Decrypt a string
  *
  * @param string  $cipher Encrypted text
  * @param string  $key    Encryption key to retrieve from the configuration, defaults to 'des_key'
  * @param boolean $base64 Whether or not input is base64-encoded
  *
  * @return string Decrypted text
  */
 public function decrypt($cipher, $key = 'des_key', $base64 = true)
 {
     if (!$cipher) {
         return '';
     }
     $cipher = $base64 ? base64_decode($cipher) : $cipher;
     $ckey = $this->config->get_crypto_key($key);
     $method = $this->config->get_crypto_method();
     $opts = defined('OPENSSL_RAW_DATA') ? OPENSSL_RAW_DATA : true;
     $iv_size = openssl_cipher_iv_length($method);
     $iv = substr($cipher, 0, $iv_size);
     // session corruption? (#1485970)
     if (strlen($iv) < $iv_size) {
         return '';
     }
     $cipher = substr($cipher, $iv_size);
     $clear = openssl_decrypt($cipher, $method, $ckey, $opts, $iv);
     return $clear;
 }