hi there, here's my code. the output on client side should be "Hello
World" but is garbage now... pls help..... thanks so much
best,
peter
crypto++ client:
=============
std::string plaintext = "Hello World", ciphertext, output;
std::string iv,key = "12345678901234567890123456789012";
iv = key;
CFB_Mode<AES>::Encryption encryption(
reinterpret_cast<const byte *>(key.c_str()),
32,
reinterpret_cast<const byte *>(iv.c_str()));
ciphertext.resize(plaintext.size());
encryption.ProcessData(reinterpret_cast<byte *>(&ciphertext[0]),
reinterpret_cast<const byte *>(plaintext.c_str()), plaintext.length());
wwwrequest("/php/decrypt.php", ciphertext, output); // output is garbage...
php server:
==========
<?php
$req = $_GET['data'];
$key = "12345678901234567890123456789012";
$iv = $key;
$td = mcrypt_module_open('rijndael-256', '', 'cfb', '');
mcrypt_generic_init($td, $key, $iv);
$resp = mdecrypt_generic($td, $req);
mcrypt_generic_deinit($td);
echo $resp;
?>
On Sat, 23 Oct 2004 23:20:09 -0400, Wei Dai <[EMAIL PROTECTED]> wrote:
> Have you read http://www.eskimo.com/~weidai/cgi-bin/fom.cgi?file=79? If
> you have, post the code you wrote using Crypto++, and explain what problem
> you are having beyond just "without success", and I'll try to help.
>
>
>
> On Sun, Oct 24, 2004 at 10:55:16AM +0800, Peter Chiu wrote:
> > dear all:
> >
> > i'm new to the list and crypto++. i am trying to write a simple
> > crypto++ program that decrypts an aes encrypted string returned from a
> > web server by php's mcrypt. i've put in several hours already without
> > success. please help!
> >
> > --
> > Best,
> > Peter
> >
> > =========== output of the mcrypt script =================
> > IV: b9MUxwBQMcTSFTKD194qbaoBfJh/NjhhZ04PuwfBL2o=
> > KEY: a7bc27daf59679de9db7b68b1ef92785
> > ENCRYPTED: yZXVQ7xT2ejGekyxv+Z8EvQYvXYZ7aJ6JPUP
> > This is very important data
> >
> > =============== here's the PHP mcrypt script: ===============
> > <?php
> > /* Open the cipher */
> > $td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
> >
> > /* Create the IV and determine the keysize length, used MCRYPT_RAND
> > * on Windows instead */
> > $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
> > echo "IV: " . base64_encode($iv) . "<br>";
> > $ks = mcrypt_enc_get_key_size($td);
> >
> > /* Create key */
> > $key = substr(md5('very secret key'), 0, $ks);
> > echo "KEY: " . $key . "<br>";
> >
> > /* Intialize encryption */
> > mcrypt_generic_init($td, $key, $iv);
> >
> > /* Encrypt data */
> > $encrypted = mcrypt_generic($td, 'This is very important data');
> > echo "ENCRYPTED: " . base64_encode ($encrypted) . "<br>";
> >
> > /* Terminate encryption handler */
> > mcrypt_generic_deinit($td);
> >
> > /* Initialize encryption module for decryption */
> > mcrypt_generic_init($td, $key, $iv);
> >
> > /* Decrypt encrypted string */
> > $decrypted = mdecrypt_generic($td, $encrypted);
> >
> > /* Terminate decryption handle and close module */
> > mcrypt_generic_deinit($td);
> > mcrypt_module_close($td);
> >
> > /* Show string */
> > echo trim($decrypted) . "\n";
> > ?>
> >
> >
> > --
> > Best,
> > Peter
>
--
Best,
Peter