2
Test mcrypt_ecb() function : usage variation
5
if (!extension_loaded("mcrypt")) {
6
print "skip - mcrypt extension not loaded";
11
/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
12
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
13
* Source code: ext/mcrypt/mcrypt.c
17
echo "*** Testing mcrypt_ecb() : usage variation ***\n";
19
// Define error handler
20
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
21
if (error_reporting() != 0) {
22
// report non-silenced errors
23
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
26
set_error_handler('test_error_handler');
28
// Initialise function arguments not being substituted (if any)
29
$cipher = MCRYPT_TRIPLEDES;
30
$data = b'string_val';
31
$mode = MCRYPT_ENCRYPT;
34
//get an unset variable
38
// define some classes
39
class classWithToString
41
public function __toString() {
42
return b"Class A object";
46
class classWithoutToString
55
// get a resource variable
56
$fp = fopen(__FILE__, "r");
59
$index_array = array (1, 2, 3);
60
$assoc_array = array ('one' => 1, 'two' => 2);
62
//array of values to iterate over
69
'int -12345' => -2345,
73
'float -10.5' => -10.5,
74
'float 12.3456789000e10' => 12.3456789000e10,
75
'float -12.3456789000e10' => -12.3456789000e10,
79
'empty array' => array(),
80
'int indexed array' => $index_array,
81
'associative array' => $assoc_array,
82
'nested arrays' => array('foo', $index_array, $assoc_array),
85
'uppercase NULL' => NULL,
86
'lowercase null' => null,
89
'lowercase true' => true,
90
'lowercase false' =>false,
91
'uppercase TRUE' =>TRUE,
92
'uppercase FALSE' =>FALSE,
95
'empty string DQ' => "",
96
'empty string SQ' => '',
99
'instance of classWithToString' => new classWithToString(),
100
'instance of classWithoutToString' => new classWithoutToString(),
103
'undefined var' => @$undefined_var,
106
'unset var' => @$unset_var,
112
// loop through each element of the array for key
114
foreach($inputs as $valueType =>$value) {
115
echo "\n--$valueType--\n";
116
var_dump(bin2hex(mcrypt_ecb($cipher, $value, $data, $mode, $iv)));
124
*** Testing mcrypt_ecb() : usage variation ***
127
string(32) "e469e6b066f9600e1eefd8f53365f96c"
130
string(32) "e469e6b066f9600e1eefd8f53365f96c"
133
string(32) "d74e5f51d1199bcfa61f80168e913007"
136
string(32) "17fe485ed735abb34c1dd4455af7b79c"
139
string(32) "cd735509aa4013a130e011686d66ae01"
142
string(32) "a57d99d6d5813039abf50fc50d631e47"
144
--float 12.3456789000e10--
145
string(32) "f17ede0bfdaa4408f545f7f4c8b040d2"
147
--float -12.3456789000e10--
148
string(32) "326f64e3b9bd5a6beb0a9b52a09a5a48"
151
string(32) "2aedf7661cd4d8c7593f44c58718e2b8"
154
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
157
--int indexed array--
158
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
161
--associative array--
162
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
166
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
170
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
173
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
176
string(32) "e469e6b066f9600e1eefd8f53365f96c"
179
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
182
string(32) "e469e6b066f9600e1eefd8f53365f96c"
185
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
188
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
191
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
193
--instance of classWithToString--
194
string(32) "1fd3514d8ced44d04d9dc7511fce33ef"
196
--instance of classWithoutToString--
197
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, object given, %s(%d)
201
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
204
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
207
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, resource given, %s(%d)