/** * Tests the encryption * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-17 */ public function testCryptEncryption() { $this->specify("encryption does not return correct results", function ($key, $test) { $modes = [MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB, MCRYPT_MODE_OFB, MCRYPT_MODE_NOFB]; $crypt = new Crypt(); foreach ($modes as $mode) { $crypt->setMode($mode); $crypt->setKey(substr($key, 0, 16)); $encryption = $crypt->encrypt($test); expect(rtrim($crypt->decrypt($encryption), ""))->equals($test); $encryption = $crypt->encrypt($test, substr($key, 0, 16)); expect(rtrim($crypt->decrypt($encryption, substr($key, 0, 16)), ""))->equals($test); } }, ['examples' => [[md5(uniqid()), str_repeat('x', mt_rand(1, 255))], [time() . time(), str_shuffle(join('', range('a', 'z')))], ['le$ki12432543543543543', null]]]); }