TestExtMcrypt -> php
Esse commit está contido em:
@@ -20,7 +20,6 @@
|
||||
#define incl_EXT_LIST_TEST_EXT_H_
|
||||
|
||||
#include "hphp/test/ext/test_ext_curl.h"
|
||||
#include "hphp/test/ext/test_ext_mcrypt.h"
|
||||
#include "hphp/test/ext/test_ext_memcached.h"
|
||||
#include "hphp/test/ext/test_ext_mysql.h"
|
||||
#include "hphp/test/ext/test_ext_pdo.h"
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "hphp/test/ext/test_ext_mcrypt.h"
|
||||
#include "hphp/runtime/ext/ext_mcrypt.h"
|
||||
#include "hphp/runtime/ext/ext_string.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtMcrypt::RunTests(const std::string &which) {
|
||||
bool ret = true;
|
||||
|
||||
RUN_TEST(test_mcrypt_module_open);
|
||||
RUN_TEST(test_mcrypt_module_close);
|
||||
RUN_TEST(test_mcrypt_list_algorithms);
|
||||
RUN_TEST(test_mcrypt_list_modes);
|
||||
RUN_TEST(test_mcrypt_module_get_algo_block_size);
|
||||
RUN_TEST(test_mcrypt_module_get_algo_key_size);
|
||||
RUN_TEST(test_mcrypt_module_get_supported_key_sizes);
|
||||
RUN_TEST(test_mcrypt_module_is_block_algorithm_mode);
|
||||
RUN_TEST(test_mcrypt_module_is_block_algorithm);
|
||||
RUN_TEST(test_mcrypt_module_is_block_mode);
|
||||
RUN_TEST(test_mcrypt_module_self_test);
|
||||
RUN_TEST(test_mcrypt_create_iv);
|
||||
RUN_TEST(test_mcrypt_encrypt);
|
||||
RUN_TEST(test_mcrypt_decrypt);
|
||||
RUN_TEST(test_mcrypt_cbc);
|
||||
RUN_TEST(test_mcrypt_cfb);
|
||||
RUN_TEST(test_mcrypt_ecb);
|
||||
RUN_TEST(test_mcrypt_ofb);
|
||||
RUN_TEST(test_mcrypt_get_block_size);
|
||||
RUN_TEST(test_mcrypt_get_cipher_name);
|
||||
RUN_TEST(test_mcrypt_get_iv_size);
|
||||
RUN_TEST(test_mcrypt_get_key_size);
|
||||
RUN_TEST(test_mcrypt_enc_get_algorithms_name);
|
||||
RUN_TEST(test_mcrypt_enc_get_block_size);
|
||||
RUN_TEST(test_mcrypt_enc_get_iv_size);
|
||||
RUN_TEST(test_mcrypt_enc_get_key_size);
|
||||
RUN_TEST(test_mcrypt_enc_get_modes_name);
|
||||
RUN_TEST(test_mcrypt_enc_get_supported_key_sizes);
|
||||
RUN_TEST(test_mcrypt_enc_is_block_algorithm_mode);
|
||||
RUN_TEST(test_mcrypt_enc_is_block_algorithm);
|
||||
RUN_TEST(test_mcrypt_enc_is_block_mode);
|
||||
RUN_TEST(test_mcrypt_enc_self_test);
|
||||
RUN_TEST(test_mcrypt_generic);
|
||||
RUN_TEST(test_mcrypt_generic_init);
|
||||
RUN_TEST(test_mdecrypt_generic);
|
||||
RUN_TEST(test_mcrypt_generic_deinit);
|
||||
RUN_TEST(test_mcrypt_generic_end);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_open() {
|
||||
Variant td = f_mcrypt_module_open("rijndael-256", "", "ofb", "");
|
||||
Variant iv = f_mcrypt_create_iv(f_mcrypt_enc_get_iv_size(td),
|
||||
k_MCRYPT_DEV_RANDOM);
|
||||
Variant ks = f_mcrypt_enc_get_key_size(td);
|
||||
Variant key = f_substr(f_md5("very secret key"), 0, ks);
|
||||
f_mcrypt_generic_init(td, key, iv);
|
||||
Variant encrypted = f_mcrypt_generic(td, "This is very important data");
|
||||
VERIFY(!same(encrypted, "This is very important data"));
|
||||
f_mcrypt_generic_deinit(td);
|
||||
f_mcrypt_generic_init(td, key, iv);
|
||||
Variant decrypted = f_mdecrypt_generic(td, encrypted);
|
||||
f_mcrypt_generic_end(td);
|
||||
f_mcrypt_module_close(td);
|
||||
|
||||
VS(decrypted, "This is very important data");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_close() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_list_algorithms() {
|
||||
VERIFY(array_value_exists(f_mcrypt_list_algorithms(), "blowfish"));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_list_modes() {
|
||||
VERIFY(array_value_exists(f_mcrypt_list_modes(), "cbc"));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_get_algo_block_size() {
|
||||
VS(f_mcrypt_module_get_algo_block_size("blowfish"), 8);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_get_algo_key_size() {
|
||||
VS(f_mcrypt_module_get_algo_key_size("blowfish"), 56);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_get_supported_key_sizes() {
|
||||
VS(f_mcrypt_module_get_supported_key_sizes("blowfish"), Array::Create());
|
||||
VS(f_mcrypt_module_get_supported_key_sizes("twofish"),
|
||||
CREATE_VECTOR3(16, 24, 32));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_is_block_algorithm_mode() {
|
||||
VS(f_mcrypt_module_is_block_algorithm_mode("cbc"), true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_is_block_algorithm() {
|
||||
VS(f_mcrypt_module_is_block_algorithm("blowfish"), true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_is_block_mode() {
|
||||
VS(f_mcrypt_module_is_block_mode("cbc"), true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_module_self_test() {
|
||||
VS(f_mcrypt_module_self_test(k_MCRYPT_RIJNDAEL_128), true);
|
||||
VS(f_mcrypt_module_self_test("bogus"), false);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_create_iv() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_encrypt() {
|
||||
String text = "boggles the inivisble monkey will rule the world";
|
||||
String key = "very secret key";
|
||||
Variant iv_size = f_mcrypt_get_iv_size(k_MCRYPT_XTEA, k_MCRYPT_MODE_ECB);
|
||||
Variant iv = f_mcrypt_create_iv(iv_size, k_MCRYPT_RAND);
|
||||
Variant enc = f_mcrypt_encrypt(k_MCRYPT_XTEA, key, text, k_MCRYPT_MODE_ECB,
|
||||
iv);
|
||||
VS(f_bin2hex(enc), "f522c62002fa16129c8576bcddc6dd0f7ea81991103ba42962d94c8bfff3ee660d53b187d7e989540abf5a729c2f7baf");
|
||||
Variant crypttext = f_mcrypt_decrypt(k_MCRYPT_XTEA, key, enc,
|
||||
k_MCRYPT_MODE_ECB, iv);
|
||||
VS(crypttext, text);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_decrypt() {
|
||||
// tested in test_mcrypt_encrypt()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_cbc() {
|
||||
String key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
String CC = "4007000000027";
|
||||
Variant encrypted =
|
||||
f_mcrypt_cbc(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
CC, k_MCRYPT_ENCRYPT, f_substr(key,32,16));
|
||||
Variant decrypted =
|
||||
f_mcrypt_cbc(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
encrypted, k_MCRYPT_DECRYPT, f_substr(key,32,16));
|
||||
VERIFY(!same(encrypted, decrypted));
|
||||
VS(decrypted.toString().data(), CC);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_cfb() {
|
||||
String key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
String CC = "4007000000027";
|
||||
Variant encrypted =
|
||||
f_mcrypt_cfb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
CC, k_MCRYPT_ENCRYPT, f_substr(key,32,16));
|
||||
Variant decrypted =
|
||||
f_mcrypt_cfb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
encrypted, k_MCRYPT_DECRYPT, f_substr(key,32,16));
|
||||
VERIFY(!same(encrypted, decrypted));
|
||||
VS(decrypted, CC);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_ecb() {
|
||||
String key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
String CC = "4007000000027";
|
||||
Variant encrypted =
|
||||
f_mcrypt_ecb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
CC, k_MCRYPT_ENCRYPT, f_substr(key,32,16));
|
||||
Variant decrypted =
|
||||
f_mcrypt_ecb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
encrypted, k_MCRYPT_DECRYPT, f_substr(key,32,16));
|
||||
VERIFY(!same(encrypted, decrypted));
|
||||
VS(decrypted.toString().data(), CC);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_ofb() {
|
||||
String key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
String CC = "4007000000027";
|
||||
Variant encrypted =
|
||||
f_mcrypt_ofb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
CC, k_MCRYPT_ENCRYPT, f_substr(key,32,16));
|
||||
Variant decrypted =
|
||||
f_mcrypt_ofb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
|
||||
encrypted, k_MCRYPT_DECRYPT, f_substr(key,32,16));
|
||||
VERIFY(!same(encrypted, decrypted));
|
||||
VS(decrypted, CC);
|
||||
return Count(true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_get_block_size() {
|
||||
VS(f_mcrypt_get_block_size("tripledes", "ecb"), 8);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_get_cipher_name() {
|
||||
VS(f_mcrypt_get_cipher_name(k_MCRYPT_TRIPLEDES), "3DES");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_get_iv_size() {
|
||||
VS(f_mcrypt_get_iv_size(k_MCRYPT_CAST_256, k_MCRYPT_MODE_CFB), 16);
|
||||
VS(f_mcrypt_get_iv_size("des", "ecb"), 8);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_get_key_size() {
|
||||
VS(f_mcrypt_get_key_size("tripledes", "ecb"), 24);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_get_algorithms_name() {
|
||||
Variant td = f_mcrypt_module_open("cast-256", "", "cfb", "");
|
||||
VS(f_mcrypt_enc_get_algorithms_name(td), "CAST-256");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_get_block_size() {
|
||||
Variant td = f_mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_get_block_size(td), 8);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_get_iv_size() {
|
||||
Variant td = f_mcrypt_module_open("cast-256", "", "cfb", "");
|
||||
VS(f_mcrypt_enc_get_iv_size(td), 16);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_get_key_size() {
|
||||
Variant td = f_mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_get_key_size(td), 24);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_get_modes_name() {
|
||||
Variant td = f_mcrypt_module_open("cast-256", "", "cfb", "");
|
||||
VS(f_mcrypt_enc_get_modes_name(td), "CFB");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_get_supported_key_sizes() {
|
||||
Variant td = f_mcrypt_module_open("rijndael-256", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_get_supported_key_sizes(td),
|
||||
CREATE_VECTOR3(16, 24, 32));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_is_block_algorithm_mode() {
|
||||
Variant td = f_mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_is_block_algorithm_mode(td), true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_is_block_algorithm() {
|
||||
Variant td = f_mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_is_block_algorithm(td), true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_is_block_mode() {
|
||||
Variant td = f_mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_is_block_mode(td), true);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_enc_self_test() {
|
||||
Variant td = f_mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(f_mcrypt_enc_self_test(td), 0);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_generic() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_generic_init() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mdecrypt_generic() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_generic_deinit() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtMcrypt::test_mcrypt_generic_end() {
|
||||
// tested in test_mcrypt_module_open()
|
||||
return Count(true);
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef incl_HPHP_TEST_EXT_MCRYPT_H_
|
||||
#define incl_HPHP_TEST_EXT_MCRYPT_H_
|
||||
|
||||
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
|
||||
|
||||
#include "hphp/test/ext/test_cpp_ext.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TestExtMcrypt : public TestCppExt {
|
||||
public:
|
||||
virtual bool RunTests(const std::string &which);
|
||||
|
||||
bool test_mcrypt_module_open();
|
||||
bool test_mcrypt_module_close();
|
||||
bool test_mcrypt_list_algorithms();
|
||||
bool test_mcrypt_list_modes();
|
||||
bool test_mcrypt_module_get_algo_block_size();
|
||||
bool test_mcrypt_module_get_algo_key_size();
|
||||
bool test_mcrypt_module_get_supported_key_sizes();
|
||||
bool test_mcrypt_module_is_block_algorithm_mode();
|
||||
bool test_mcrypt_module_is_block_algorithm();
|
||||
bool test_mcrypt_module_is_block_mode();
|
||||
bool test_mcrypt_module_self_test();
|
||||
bool test_mcrypt_create_iv();
|
||||
bool test_mcrypt_encrypt();
|
||||
bool test_mcrypt_decrypt();
|
||||
bool test_mcrypt_cbc();
|
||||
bool test_mcrypt_cfb();
|
||||
bool test_mcrypt_ecb();
|
||||
bool test_mcrypt_ofb();
|
||||
bool test_mcrypt_get_block_size();
|
||||
bool test_mcrypt_get_cipher_name();
|
||||
bool test_mcrypt_get_iv_size();
|
||||
bool test_mcrypt_get_key_size();
|
||||
bool test_mcrypt_enc_get_algorithms_name();
|
||||
bool test_mcrypt_enc_get_block_size();
|
||||
bool test_mcrypt_enc_get_iv_size();
|
||||
bool test_mcrypt_enc_get_key_size();
|
||||
bool test_mcrypt_enc_get_modes_name();
|
||||
bool test_mcrypt_enc_get_supported_key_sizes();
|
||||
bool test_mcrypt_enc_is_block_algorithm_mode();
|
||||
bool test_mcrypt_enc_is_block_algorithm();
|
||||
bool test_mcrypt_enc_is_block_mode();
|
||||
bool test_mcrypt_enc_self_test();
|
||||
bool test_mcrypt_generic();
|
||||
bool test_mcrypt_generic_init();
|
||||
bool test_mdecrypt_generic();
|
||||
bool test_mcrypt_generic_deinit();
|
||||
bool test_mcrypt_generic_end();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // incl_HPHP_TEST_EXT_MCRYPT_H_
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
function VS($x, $y) {
|
||||
var_dump($x === $y);
|
||||
if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
|
||||
var_dump(debug_backtrace()); }
|
||||
}
|
||||
function VERIFY($x) { VS($x != false, true); }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
$td = mcrypt_module_open("rijndael-256", "", "ofb", "");
|
||||
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),
|
||||
MCRYPT_DEV_RANDOM);
|
||||
$ks = mcrypt_enc_get_key_size($td);
|
||||
$key = substr(md5("very secret key"), 0, $ks);
|
||||
mcrypt_generic_init($td, $key, $iv);
|
||||
$encrypted = mcrypt_generic($td, "This is very important data");
|
||||
VERIFY($encrypted !== "This is very important data");
|
||||
mcrypt_generic_deinit($td);
|
||||
mcrypt_generic_init($td, $key, $iv);
|
||||
$decrypted = mdecrypt_generic($td, $encrypted);
|
||||
mcrypt_generic_end($td);
|
||||
mcrypt_module_close($td);
|
||||
|
||||
VS($decrypted, "This is very important data");
|
||||
|
||||
VERIFY(in_array("blowfish", mcrypt_list_algorithms()));
|
||||
VERIFY(in_array("cbc", mcrypt_list_modes()));
|
||||
VS(mcrypt_module_get_algo_block_size("blowfish"), 8);
|
||||
VS(mcrypt_module_get_algo_key_size("blowfish"), 56);
|
||||
|
||||
VS(mcrypt_module_get_supported_key_sizes("blowfish"), array());
|
||||
VS(mcrypt_module_get_supported_key_sizes("twofish"),
|
||||
array(16, 24, 32));
|
||||
|
||||
VS(mcrypt_module_is_block_algorithm_mode("cbc"), true);
|
||||
VS(mcrypt_module_is_block_algorithm("blowfish"), true);
|
||||
VS(mcrypt_module_is_block_mode("cbc"), true);
|
||||
VS(mcrypt_module_self_test(MCRYPT_RIJNDAEL_128), true);
|
||||
VS(mcrypt_module_self_test("bogus"), false);
|
||||
|
||||
$text = "boggles the inivisble monkey will rule the world";
|
||||
$key = "very secret key";
|
||||
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
|
||||
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
|
||||
$enc = mcrypt_encrypt(MCRYPT_XTEA, $key, $text, MCRYPT_MODE_ECB,
|
||||
$iv);
|
||||
VS(bin2hex($enc), "f522c62002fa16129c8576bcddc6dd0f7ea81991103ba42962d94c8bfff3ee660d53b187d7e989540abf5a729c2f7baf");
|
||||
$crypttext = mcrypt_decrypt(MCRYPT_XTEA, $key, $enc,
|
||||
MCRYPT_MODE_ECB, $iv);
|
||||
VS($crypttext, $text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
$key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
$CC = "4007000000027";
|
||||
$encrypted =
|
||||
mcrypt_cbc(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$CC, MCRYPT_ENCRYPT, substr($key,32,16));
|
||||
$decrypted =
|
||||
mcrypt_cbc(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$encrypted, MCRYPT_DECRYPT, substr($key,32,16));
|
||||
VERIFY($encrypted !== $decrypted);
|
||||
VS(trim((string)$decrypted), $CC);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
$key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
$CC = "4007000000027";
|
||||
$encrypted =
|
||||
mcrypt_cfb(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$CC, MCRYPT_ENCRYPT, substr($key,32,16));
|
||||
$decrypted =
|
||||
mcrypt_cfb(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$encrypted, MCRYPT_DECRYPT, substr($key,32,16));
|
||||
VERIFY($encrypted !== $decrypted);
|
||||
VS(trim((string)$decrypted), $CC);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
$key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
$CC = "4007000000027";
|
||||
$encrypted =
|
||||
mcrypt_ecb(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$CC, MCRYPT_ENCRYPT, substr($key,32,16));
|
||||
$decrypted =
|
||||
mcrypt_ecb(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$encrypted, MCRYPT_DECRYPT, substr($key,32,16));
|
||||
VERIFY($encrypted !== $decrypted);
|
||||
VS(trim((string)$decrypted), $CC);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
$key = "123456789012345678901234567890123456789012345678901234567890";
|
||||
$CC = "4007000000027";
|
||||
$encrypted =
|
||||
mcrypt_ofb(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$CC, MCRYPT_ENCRYPT, substr($key,32,16));
|
||||
$decrypted =
|
||||
mcrypt_ofb(MCRYPT_RIJNDAEL_128, substr($key,0,32),
|
||||
$encrypted, MCRYPT_DECRYPT, substr($key,32,16));
|
||||
VERIFY($encrypted !== $decrypted);
|
||||
VS($decrypted, $CC);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
VS(mcrypt_get_block_size("tripledes", "ecb"), 8);
|
||||
VS(mcrypt_get_cipher_name(MCRYPT_TRIPLEDES), "3DES");
|
||||
VS(mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB), 16);
|
||||
VS(mcrypt_get_iv_size("des", "ecb"), 8);
|
||||
VS(mcrypt_get_key_size("tripledes", "ecb"), 24);
|
||||
|
||||
$td = mcrypt_module_open("cast-256", "", "cfb", "");
|
||||
VS(mcrypt_enc_get_algorithms_name($td), "CAST-256");
|
||||
|
||||
$td = mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(mcrypt_enc_get_block_size($td), 8);
|
||||
|
||||
$td = mcrypt_module_open("cast-256", "", "cfb", "");
|
||||
VS(mcrypt_enc_get_iv_size($td), 16);
|
||||
|
||||
$td = mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(mcrypt_enc_get_key_size($td), 24);
|
||||
|
||||
$td = mcrypt_module_open("cast-256", "", "cfb", "");
|
||||
VS(mcrypt_enc_get_modes_name($td), "CFB");
|
||||
|
||||
$td = mcrypt_module_open("rijndael-256", "", "ecb", "");
|
||||
VS(mcrypt_enc_get_supported_key_sizes($td),
|
||||
array(16, 24, 32));
|
||||
|
||||
$td = mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(mcrypt_enc_is_block_algorithm_mode($td), true);
|
||||
|
||||
$td = mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(mcrypt_enc_is_block_algorithm($td), true);
|
||||
|
||||
$td = mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(mcrypt_enc_is_block_mode($td), true);
|
||||
|
||||
$td = mcrypt_module_open("tripledes", "", "ecb", "");
|
||||
VS(mcrypt_enc_self_test($td), 0);
|
||||
@@ -0,0 +1,38 @@
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
Referência em uma Nova Issue
Bloquear um usuário