public function testEncryptByPassword() { $data = 'known data'; $key = 'secret'; $encryptedData = $this->security->encryptByPassword($data, $key); $this->assertFalse($data === $encryptedData); $decryptedData = $this->security->decryptByPassword($encryptedData, $key); $this->assertEquals($data, $decryptedData); $tampered = $encryptedData; $tampered[20] = ~$tampered[20]; $decryptedData = $this->security->decryptByPassword($tampered, $key); $this->assertTrue(false === $decryptedData); }
/** * @dataProvider dataProviderEncryptByPasswordCompat * * @param string $password encryption password * @param string $data plaintext hex string * @param string $encrypted ciphertext hex string */ public function testEncryptByPasswordCompat($password, $data, $encrypted) { $data = hex2bin(preg_replace('{\\s+}', '', $data)); $encrypted = hex2bin(preg_replace('{\\s+}', '', $encrypted)); $this->assertEquals($data, $this->security->decryptByPassword($encrypted, $password)); }