Bạn có thể sử dụng những ý tưởng lập trình nói chung mà không cần dựa vào xây dựng trong mã hóa/chức năng decription Ví dụ tạo một hàm gọi nó là
function encryptstring($string) {
$string_length=strlen($string);
$encrychars="";
/**
*For each character of the given string generate the code
*/
for ($position = 0;$position<$string_length;$position++){
$key = (($string_length+$position)+1);
$key = (255+$key) % 255;
$get_char_to_be_encrypted = SUBSTR($string, $position, 1);
$ascii_char = ORD($get_char_to_be_encrypted);
$xored_char = $ascii_char^$key; //xor operation
$encrypted_char = CHR($xored_char);
$encrychars .= $encrypted_char;
}
/**
*Return the encrypted/decrypted string
*/
return $encrychars;
}
Trên trang với liên kết để bao gồm các id của yêu cầu phải được mã hóa
/**
*While passing the unique value to a link
*Do the following steps
*/
$id=57;//or if you are fetching it automatically just pass it here
/**
*For more security multiply some value
*You can set the multiplication value in config file
*/
$passstring=$id*346244;
$encrypted_string=encryptstring($passstring);
$param=urlencode($encrypted_string);
/**
*Derive the url for the link
*/
echo '<a href="target_file.php?aZ98#9A_KL='.$param.'">something</a>' ;
Trên tập tin mục tiêu mà có được mở sau khi liên kết được nhấp
/**
*Retriving the value in the target file
*Do the following steps
*/
$fetchid=$_GET['aZ98#9A_KL'];
$passstring=urldecode(stripslashes($fetchid));
$decrypted_string= encryptstring($passstring);
/**
*Divide the decrypted value with the same value we used for the multiplication
*/
$actual_id= $decrypted_string/346244;
Nguồn
2014-09-20 21:09:13
3-20 nhân vật, đây không phải là mật khẩu, phải không? Mã hóa một chiều hầu như luôn là lựa chọn tốt hơn cho mật khẩu. –