I cannot seem to get the same encrypted output for the same data, between the two methods. I've tried to ensure I am using the same algorithms and modes for both methods by testing the mcrypt_enc_get_* functions. I think the problem may lie in the way both methods are being seeded.
Web-Based PHP Example:
$key = 'test'; $data[] = 'abcdefghijklmnopqrstuvwxyz'; $m = 0;
foreach ($data as $dt) { $td = mcrypt_module_open('tripledes', '', 'ecb', ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $CRYPT[$m] = mcrypt_generic($td, $dt);
/* echo mcrypt_enc_get_algorithms_name($td); echo mcrypt_enc_get_block_size($td); echo mcrypt_enc_get_iv_size($td); echo mcrypt_enc_get_key_size($td); echo mcrypt_enc_get_modes_name($td); echo mcrypt_enc_get_supported_key_sizes($td); echo mcrypt_enc_is_block_algorithm_mode($td); echo mcrypt_enc_is_block_algorithm($td); echo mcrypt_enc_is_block_mode($td); echo mcrypt_enc_self_test($td); */
$DECRYPT[$m] = mdecrypt_generic($td, $dt); mcrypt_generic_deinit($td); mcrypt_module_close($td);
echo "crypt_" . base64_encode($CRYPT[$m]) . "_<br />\n"; echo "decrypt_" . base64_decode(rtrim($DECRYPT[$m])) . "_<br />\n";
$m++; }
Note: I believe it is the line where the $iv variable is being set that is causing the issue and/or I cannot reproduce the same seeding using the command line options.
Command Line Example:
echo "abcdefghijklmnopqrstuvwxyz" | mcrypt -Fb -m ecb -a tripledes | encode-base64
echo "" | decode-base64 | mcrypt -dFb -m ecb -a tripledes
I would appreciate any comments or suggestions.
Respectfully,
Gary
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php