Hello!

I'm trying to use mcrypt to encrypt some values (login and password) I have
to pass from one website to another.
I thook this code from the php.net website as an example:

<?php
    /* Open the cipher */
    $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');

    /* Create the IV and determine the keysize length */
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
    $ks = mcrypt_enc_get_key_size ($td);

    /* Create key */
    $key = substr (md5 ('very secret key'), 0, $ks);

    /* Intialize encryption */
    mcrypt_generic_init ($td, $key, $iv);

    /* Encrypt data */
    $encrypted = mcrypt_generic ($td, 'This is very important data');

    /* 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";
?>

I put this in the page starting from:

<?php
    $adminlogin = $row1["adminlogin"];
    $adminpw = $row1["adminpw"];
    // both are queried from a database

    $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
    $ks = mcrypt_enc_get_key_size ($td);
    $key = substr (md5 ('a key fsfqz'), 0, $ks);
    mcrypt_generic_init ($td, $key, $iv);

    /* Encrypt data */
    $encryptedlogin = mcrypt_generic ($td, $adminlogin);
    $encryptedpassw = mcrypt_generic ($td, $adminpw);

    mcrypt_generic_deinit ($td);
    mcrypt_module_close ($td);
?>
<a href="destinationpage.php?login=<?php echo("$encryptedlogin");
?>&password=<?php echo("$encryptedpassw"); ?>" target="_blank">link</a>


In the destination page (destinationpage.php, on a different server) I have
this:

      $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
      $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td),
MCRYPT_DEV_RANDOM);
      $ks = mcrypt_enc_get_key_size ($td);
      $key = substr (md5 ('a key fsfqz'), 0, $ks);
      mcrypt_generic_init ($td, $key, $iv);

      /* Decrypt encrypted string */
      $login = mdecrypt_generic ($td, $login);
      $login = trim ($login);
      $password = mdecrypt_generic ($td, $password);
      $password = trim ($password);

      mcrypt_generic_deinit ($td);
      mcrypt_module_close ($td);

  and then an echo("$login - $password<br>"); to check if the values are
correct.

But they are not!!
What am I doing wrong?? Is it because both are on a different server?
I would very much appreciate your help. Or if someone has an other good way
of encrypting values, please let me know!

Thanks!!!

Mark.

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

Reply via email to