Page 1 of 1

Need help in encryption and decryption

Posted: Wed Mar 25, 2009 3:56 am
by susrisha
I have been trying to print the encrypted string of the given string using mcrypt_encrypt algorithm.

Here is the code that i have

Code: Select all

 
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $key = "somekey";
    $text = "Hello there";
   
   
    
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
    
    
    echo $crypttext;
 
I am able to decrypt them properly using the decrypt function.

Here is the problem. I believe this is the AES algorithm. i got one more solution in C# which does the same AES encoding but the values are differing from each other. My encrypted text when echoed gives out special characters, the C# gives hex characters i suppose. Can any one give me a solution for the same.

Thanks in advance.

Re: Need help in encryption and decryption

Posted: Wed Mar 25, 2009 4:01 am
by Benjamin
You want to base64_encode it. Also, encrypting the same string will result in a different encrypted string each time.

Re: Need help in encryption and decryption

Posted: Wed Mar 25, 2009 5:09 am
by susrisha
will try and let you know