xeonyk Posted June 6, 2007 Share Posted June 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54408-problem-with-encryption-query-string/ Share on other sites More sharing options...
mmarif4u Posted June 6, 2007 Share Posted June 6, 2007 In the testing.php u have to use GET to retrieve the value of code. Also add ur function to that page. testing.php <?php require_once("function.php"); $code=$_GET['code']; $code1=decrypt($code); echo $code1; ?> Hope this will help. Quote Link to comment https://forums.phpfreaks.com/topic/54408-problem-with-encryption-query-string/#findComment-269029 Share on other sites More sharing options...
xeonyk Posted June 6, 2007 Author Share Posted June 6, 2007 i have try but the value encrypt and decrypt is different for some value like L00002 when i try L00001 it work good can anyone give me other tutorial? Quote Link to comment https://forums.phpfreaks.com/topic/54408-problem-with-encryption-query-string/#findComment-269030 Share on other sites More sharing options...
mmarif4u Posted June 6, 2007 Share Posted June 6, 2007 Oh 1st u hash the keyword with md5 so sorry man its not possible to unhash the md5 hash, So definitely it will give u the different value. Quote Link to comment https://forums.phpfreaks.com/topic/54408-problem-with-encryption-query-string/#findComment-269033 Share on other sites More sharing options...
xeonyk Posted June 6, 2007 Author Share Posted June 6, 2007 it not work i change my key into string "hehe" it result still same, some value not same when encrypted Quote Link to comment https://forums.phpfreaks.com/topic/54408-problem-with-encryption-query-string/#findComment-269057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.