Decrypt cyphertext
public static decrypt ( string $cyphertext, string $password, integer $cost, string $cipher = MCRYPT_RIJNDAEL_128, string $mode = MCRYPT_MODE_CBC, string $algo = 'sha256' ) : string | boolean | ||
$cyphertext | string | Cypher text to decrypt |
$password | string | Password that should be used to decrypt input data |
$cost | integer | Number of HMAC iterations to perform on key |
$cipher | string | Mcrypt cipher |
$mode | string | Mcrypt mode |
$algo | string | Hashing algorithm to use for internal operations |
Результат | string | boolean | Returns false on checksum validation failure |
public function testCrossCompatability() { // If PHP 7.1, skip this test if (self::mcryptDeprecated()) { $this->assertTrue(true); return; } $k = 'asdf'; $p = '1234'; $c = Aes::encrypt($p, $k); $this->assertEquals($p, Mcrypt::decrypt($c, $k)); }
public function testEngine() { // If PHP 7.1, skip this test if (self::mcryptDeprecated()) { $this->assertTrue(true); return; } $modes = self::mcryptModes(); $ciphers = self::mcryptCiphers(); foreach (hash_algos() as $algo) { $input = 'AAAAAAAA'; $key = 'AAAAAAAA'; $cost = 0; foreach ($modes as $mode) { foreach ($ciphers as $cipher) { $encrypted = Mcrypt::encrypt($input, $key, $cost, $cipher, $mode, $algo); $this->assertEquals($input, Mcrypt::decrypt($encrypted, $key, $cost, $cipher, $mode, $algo)); } } } }
public function testCrossDecryptFailure() { $pw = 'password'; $encrypted = \Dcrypt\Aes::encrypt('hello world', $pw); try { \Dcrypt\AesCtr::decrypt($encrypted, $pw); $this->assertTrue(false); } catch (\Exception $ex) { $this->assertTrue(true); } try { \Dcrypt\Mcrypt::decrypt($encrypted, $pw); $this->assertTrue(false); } catch (\Exception $ex) { $this->assertTrue(true); } $encrypted = \Dcrypt\AesCtr::encrypt('hello world', $pw); try { \Dcrypt\Aes::decrypt($encrypted, $pw); $this->assertTrue(false); } catch (\Exception $ex) { $this->assertTrue(true); } }