2 /* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
3 * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
4 * Source code: ext/mcrypt/mcrypt.c
8 echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
10 // Define error handler
11 function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
12 if (error_reporting() != 0) {
13 // report non-silenced errors
14 echo "Error: $err_no - $err_msg, $filename($linenum)\n";
17 set_error_handler('test_error_handler');
19 // Initialise function arguments not being substituted (if any)
20 $cipher = MCRYPT_TRIPLEDES
;
22 $data = b
'string_val';
23 //in php, it incorrectly reports problems with iv in ECB mode.
24 $mode = MCRYPT_MODE_CBC
;
26 //get an unset variable
30 // define some classes
31 class classWithToString
33 public function __toString() {
34 return b
"Class A object";
38 class classWithoutToString
47 // get a resource variable
48 $fp = fopen(__FILE__
, "r");
51 $index_array = array (1, 2, 3);
52 $assoc_array = array ('one' => 1, 'two' => 2);
54 //array of values to iterate over
61 'int -12345' => -2345,
65 'float -10.5' => -10.5,
66 'float 12.3456789000e10' => 12.3456789000e10
,
67 'float -12.3456789000e10' => -12.3456789000e10
,
71 'empty array' => array(),
72 'int indexed array' => $index_array,
73 'associative array' => $assoc_array,
74 'nested arrays' => array('foo', $index_array, $assoc_array),
77 'uppercase NULL' => NULL,
78 'lowercase null' => null,
81 'lowercase true' => true,
82 'lowercase false' =>false,
83 'uppercase TRUE' =>TRUE,
84 'uppercase FALSE' =>FALSE,
87 'empty string DQ' => "",
88 'empty string SQ' => '',
91 'instance of classWithToString' => new classWithToString(),
92 'instance of classWithoutToString' => new classWithoutToString(),
95 'undefined var' => @$undefined_var,
98 'unset var' => @$unset_var,
104 // loop through each element of the array for iv
106 foreach($inputs as $valueType =>$value) {
107 echo "\n--$valueType--\n";
108 var_dump( bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $value)));