Jump to content

problem with encryption query string


xeonyk

Recommended Posts

i have this code :

 

$security_keyword = md5("testing");

 

and i have this 2 function in function.php:

 

            function encrypt($data_input)
            {      
   		global $security_keyword;

	$key = $security_keyword;
	$td = mcrypt_module_open('cast-256', '', 'ecb', ''); 
	$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); 
	mcrypt_generic_init($td, $key, $iv); 
	$encrypted_data = mcrypt_generic($td, $data_input); 
	mcrypt_generic_deinit($td); 
	mcrypt_module_close($td); 
	$encoded_64=base64_encode($encrypted_data); 
	return $encoded_64; 
}    


function decrypt($encoded_64)
{ 
	global $security_keyword;

	$decoded_64=base64_decode($encoded_64); 
	$key = $security_keyword;// same as you used to encrypt 
	$td = mcrypt_module_open('cast-256', '', 'ecb', ''); 
	$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); 
	mcrypt_generic_init($td, $key, $iv); 
	$decrypted_data = mdecrypt_generic($td, $decoded_64); 
	mcrypt_generic_deinit($td); 
	mcrypt_module_close($td); 
	return trim($decrypted_data); 
}

 

and i have two page index.php and testing.php

 

index.php

require_once("function.php");
$code = encrypt("L00002");
echo "<a href=\"testing.php?code=".$code."\">click</a>";

 

testing.php

$code = decrypt("L00002");
echo $code;

 

the result before encrypt and decrypt is different for some value, what must i do?

or some body can show me how to encrypt query string but it have same value before encrypt and after decrypt?

 

i have search at google but when i try the value always different for some value.

 

thx

Link to comment
https://forums.phpfreaks.com/topic/54408-problem-with-encryption-query-string/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.