Jump to content

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.