print "AES-192 otv decrypted is ok: " . bool_str(Base16::encode($aes192tvd) == "00112233445566778899aabbccddeeff") . "<br/>\n"; print "AES-192 (CBC mode) encrypted in UTF-8: " . Base16::encode($aes192e) . "<br/>\n"; print "AES-192 (CBC mode) decrypted in UTF-8: " . $aes192d . "<br/><br/>\n"; /** * Test AES-256 with one official test vector and custom input. * Vectors from: http://www.csrc.nist.gov/publications/fips/fips197/fips-197.pdf */ $aes256tvk = pack("c*", 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f); $aes256tvt = pack("c*", 0x0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff); $aes256tve = AES::encrypt($aes256tvk, $aes256tvt); // ECB mode, no padding needed. $aes256tvd = AES::decrypt($aes256tvk, $aes256tve); // ECB mode, no padding needed. // $aes256i = "1234567890123456"; $aes256k = "12345678901234561234567890123456"; $aes256e = AES::encrypt($aes256k, PKCS7::pad($input, 16), "ctr", $aes256i); // Needs padding. $aes256d = PKCS7::unpad(AES::decrypt($aes256k, $aes256e, "ctr", $aes256i)); // Needs unpadding. // print "AES-256 otv encrypted is ok: " . bool_str(Base16::encode($aes256tve) == "8ea2b7ca516745bfeafc49904b496089") . "<br/>\n"; print "AES-256 otv decrypted is ok: " . bool_str(Base16::encode($aes256tvd) == "00112233445566778899aabbccddeeff") . "<br/>\n"; print "AES-256 (CTR mode) encrypted in UTF-8: " . Base16::encode($aes256e) . "<br/>\n"; print "AES-256 (CTR mode) decrypted in UTF-8: " . $aes256d . "<br/><br/>\n"; ?> </div> </body> </html>
public function testBadDecode() { // bad char bigger than blocksize $badpad = "1234567\t"; $this->assertFalse(PKCS7::unpad($badpad, 8)); // bad char -- 0 $badpad = "1234567"; $this->assertFalse(PKCS7::unpad($badpad, 8)); // string wrong length $badpad = "1234567"; $this->assertFalse(PKCS7::unpad($badpad, 8)); // padding corrupted $this->assertFalse(PKCS7::unpad("12", 8)); }