mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-27 09:08:24 +00:00
Crypt/Base: fix decryption for ECB / CBC on PHP < 5.4.0
This commit is contained in:
parent
8f27aaa323
commit
31af2b3ed3
@ -990,10 +990,20 @@ class Crypt_Base
|
|||||||
}
|
}
|
||||||
switch ($this->mode) {
|
switch ($this->mode) {
|
||||||
case CRYPT_MODE_STREAM:
|
case CRYPT_MODE_STREAM:
|
||||||
|
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
|
||||||
|
break;
|
||||||
case CRYPT_MODE_ECB:
|
case CRYPT_MODE_ECB:
|
||||||
|
if (!defined('OPENSSL_RAW_DATA')) {
|
||||||
|
$padding = str_repeat(chr($this->block_size), $this->block_size);
|
||||||
|
$ciphetext.= openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true);
|
||||||
|
}
|
||||||
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
|
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
|
||||||
break;
|
break;
|
||||||
case CRYPT_MODE_CBC:
|
case CRYPT_MODE_CBC:
|
||||||
|
if (!defined('OPENSSL_RAW_DATA')) {
|
||||||
|
$padding = str_repeat(chr($this->block_size), $this->block_size) ^ substr($ciphertext, -$block_size);
|
||||||
|
$plaintext.= openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true);
|
||||||
|
}
|
||||||
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->decryptIV);
|
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->decryptIV);
|
||||||
if ($this->continuousBuffer) {
|
if ($this->continuousBuffer) {
|
||||||
$this->decryptIV = substr($ciphertext, -$this->block_size);
|
$this->decryptIV = substr($ciphertext, -$this->block_size);
|
||||||
@ -1528,7 +1538,8 @@ class Crypt_Base
|
|||||||
$this->openssl_emulate_ctr = false;
|
$this->openssl_emulate_ctr = false;
|
||||||
$result = $this->cipher_name_openssl &&
|
$result = $this->cipher_name_openssl &&
|
||||||
extension_loaded('openssl') &&
|
extension_loaded('openssl') &&
|
||||||
version_compare(PHP_VERSION, '5.3.0');
|
// PHP 5.3.0 - 5.3.2 did not let you set IV's
|
||||||
|
version_compare(PHP_VERSION, '5.3.3', '>=');
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user