Re: web-based and command line mcrypting and back again

From: Date: Tue, 06 Jan 2004 22:54:16 +0000
Subject: Re: web-based and command line mcrypting and back again
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-173923@lists.php.net to get a copy of this message
Tom, I appreciate the suggestion, but even after setting the iv to zero within the php code and including the --noiv option within the command line; it still does not produce the same base64 encoded string under both methods. I noticed that the command line was keying off of 2 passphrases and the php code off of only 1, so I forced the command line to key off of only 1 passphrase--to no avail. I am obviously missing something. Someone out there has had to have done this at least once before. Any other suggestions would be appreciated. Respectfully, Gary Tom Rogers wrote:
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);


« previous php.general (#173923) next »