/** * Tests the padding * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-17 */ public function testCryptPadding() { $this->specify("padding not return correct results", function () { $texts = ['']; $key = '0123456789ABCDEF0123456789ABCDEF'; $ciphers = ['AES-256-ECB', 'AES-256-CBC', 'AES-256-CFB']; $pads = [Crypt::PADDING_ANSI_X_923, Crypt::PADDING_PKCS7, Crypt::PADDING_ISO_10126, Crypt::PADDING_ISO_IEC_7816_4, Crypt::PADDING_ZERO, Crypt::PADDING_SPACE]; for ($i = 1; $i < 128; ++$i) { $texts[] = str_repeat('A', $i); } $crypt = new Crypt(); $crypt->setKey(substr($key, 0, 32)); foreach ($pads as $padding) { $crypt->setPadding($padding); foreach ($ciphers as $cipher) { $crypt->setCipher($cipher); foreach ($texts as $text) { $encrypted = $crypt->encrypt($text); $actual = $crypt->decrypt($encrypted); expect($actual)->equals($text); } } } }); }