Hi,

Tuesday, January 6, 2004, 8:48:17 PM, you wrote:
GCN> I am trying to figure out how to encrypt data using the web-based php
GCN> mcrypt function and then decrypt it using the command line (cli) mcrypt
GCN> binary, and vica-versa.

GCN> I cannot seem to get the same encrypted output for the same data,
GCN> between the two methods.  I've tried to ensure I am using the same
GCN> algorithms and modes for both methods by testing the mcrypt_enc_get_*
GCN> functions.  I think the problem may lie in the way both methods are
GCN> being seeded.

GCN> Web-Based PHP Example:

GCN> $key = 'test';
GCN> $data[] = 'abcdefghijklmnopqrstuvwxyz';
GCN> $m = 0;

GCN> foreach ($data as $dt)
GCN> {
GCN>     $td = mcrypt_module_open('tripledes', '', 'ecb', '');
GCN>     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
GCN>     mcrypt_generic_init($td, $key, $iv);
GCN>     $CRYPT[$m] = mcrypt_generic($td, $dt);

GCN> /*
GCN>     echo mcrypt_enc_get_algorithms_name($td);
GCN>     echo mcrypt_enc_get_block_size($td);
GCN>     echo mcrypt_enc_get_iv_size($td);
GCN>     echo mcrypt_enc_get_key_size($td);
GCN>     echo mcrypt_enc_get_modes_name($td);
GCN>     echo mcrypt_enc_get_supported_key_sizes($td);
GCN>     echo mcrypt_enc_is_block_algorithm_mode($td);
GCN>     echo mcrypt_enc_is_block_algorithm($td);
GCN>     echo mcrypt_enc_is_block_mode($td);
GCN>     echo mcrypt_enc_self_test($td);
GCN> */

GCN>     $DECRYPT[$m] = mdecrypt_generic($td, $dt);
GCN>     mcrypt_generic_deinit($td);
GCN>     mcrypt_module_close($td);

GCN>     echo "crypt_" . base64_encode($CRYPT[$m]) . "_<br />\n";
GCN>     echo "decrypt_" . base64_decode(rtrim($DECRYPT[$m])) . "_<br />\n";

GCN>     $m++;
GCN> }

GCN> Note:  I believe it is the line where the $iv variable is being set that
GCN> is causing the issue and/or I cannot reproduce the same seeding using
GCN> the command line options.


GCN> Command Line Example:

GCN> echo "abcdefghijklmnopqrstuvwxyz" | mcrypt -Fb -m ecb -a tripledes |
GCN> encode-base64

GCN> echo "" | decode-base64 | mcrypt -dFb -m ecb -a tripledes


GCN> I would appreciate any comments or suggestions.

GCN> Respectfully,


GCN> Gary


try setting the iv to all 0's
$iv = 0;
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to