Problem with Rindael-128 encryption

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
messier79
Forum Newbie
Posts: 4
Joined: Sun Oct 31, 2010 1:49 pm

Problem with Rindael-128 encryption

Post by messier79 »

Hi

Here is a weird problem. I have that function :

Code: Select all

		private function aes_encrypt($data){
			if($data == ''){
				return($data);
			}
			$td = mcrypt_module_open('rijndael-128', '', 'ecb', '');
			$public_key = base64_decode($this->getKey());
			$iv_size = mcrypt_enc_get_iv_size($td);
			$iv = '0000000000000000';
			
			if (mcrypt_generic_init($td, $public_key, $iv) != -1) {
				// Encrypt
				$encrypted = mcrypt_generic($td, $data);
				mcrypt_generic_deinit($td);
			
				// Clean
				//mcrypt_generic_deinit($td);
				mcrypt_module_close($td);
				
				$encrypted = base64_encode($encrypted);
				//echo $data.'<br>';
				//echo $encrypted.'<br>';
			}
			
			return($encrypted);
		}
It encrypt a string received in the parameter $data.
In full PHP, it works well, but if I want to decrypt using another lamguage, it crashes.
The funny thing is, if I put the string I want to encrypt directly hardcoded in the function :

Code: Select all

$data = 'My string to encrypt';
it works. But, if it is a param, it doesn't...

Any Idea ?
Thanks
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Problem with Rindael-128 encryption

Post by Weirdan »

Since it's not PHP that crashes (at least this is how understood it) you need to post the code in that language you use to decrypt at least.
Post Reply