2

I have the following Encryption Classs in php

define(ENCRYPTION_KEY,"abcdegef");
define(INITIALIZATION_VECTOR,mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB), MCRYPT_RAND));

function EncryptString($input)
{
    $encrypted_string = mcrypt_encrypt(MCRYPT_DES, ENCRYPTION_KEY, $input, MCRYPT_MODE_CBC, INITIALIZATION_VECTOR);
    return base64_encode($encrypted_string);
}

function DecryptString($encryptedInput)
{
    $decrypted_string = mcrypt_decrypt(MCRYPT_DES, ENCRYPTION_KEY, base64_decode($encryptInput), MCRYPT_MODE_CBC, INITIALIZATION_VECTOR);
    return $decrypted_string;
}  

And have url on anchor tag with querystring which i am encrypting

<a href="SomePage.php?action=<?php include_once ('EncryptionLibrary.php');
echo EncryptString("IamData"); ?>

When I am trying to decrypt it on SomePage.php using following code .. I am getting decrypted value incorrect

if (isset($_GET["action"]))
{
        echo trim(DecryptString($_GET["action"]));
}
1
  • I am encrypting by <a href="SomePage.php?action=<\?php include_once('EncryptionLibrary.php'); echo EncryptString("IamData"); \?>" Commented Dec 16, 2009 at 13:54

1 Answer 1

2

The value of INITIALIZATION_VECTOR is different each time. For modes that use an IV you need the same one for encryption and decryption.

Sign up to request clarification or add additional context in comments.

1 Comment

Options. (a) Use a mode (like EBC) that doesn't use an IV. (b) Send the IV to the page (it doesn't need to be secret). (c) Create the IV once, by hand. Hardcode it [], perhaps using serialize and unserialize. [] I can't believe I'm advising you to hardcode data. Don't tell anyone I said that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.