Need help in encryption and decryption

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Need help in encryption and decryption

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need help in encryption and decryption

Post by Benjamin »

You want to base64_encode it. Also, encrypting the same string will result in a different encrypted string each time.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Need help in encryption and decryption

Post by susrisha »

will try and let you know
Post Reply