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>
function array_str($arr, $var_export_all = false) { $is_assoc = is_assoc($arr); $result = '['; foreach ($arr as $key => $value) { if ($is_assoc) { $result .= $key . '='; } if (is_array($value)) { $result .= array_str($value); } else { if ($var_export_all) { $result .= var_export($value, true); } else { if (is_bool($value)) { $result .= bool_str($value); } else { if (is_string($value)) { $result .= '"' . $value . '"'; } else { if (is_string_convertable($value)) { $result .= $value; } else { $result .= var_export($value, true); } } } } } $result .= ', '; } return remove_last($result, ', ') . ']'; }