AsCENT & MaNGOS
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[PHP] Mcrypt ¾Ïȣȭ/º¹È£È­

Go down

[PHP] Mcrypt ¾Ïȣȭ/º¹È£È­ Empty [PHP] Mcrypt ¾Ïȣȭ/º¹È£È­

¿Ã¸®±â by Admin 2009-12-13, 10:31 pm

function encrypt($string,$key) {
srand((double) microtime() * 1000000);
$key = md5($key);
$td = mcrypt_module_open('des', '','cfb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
if (mcrypt_generic_init($td, $key, $iv) != -1) {
$c_t = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$c_t = $iv.$c_t;
return $c_t;
}
}

$id= encrypt(english,title);

<a href=view.php?id=<?=htmlentities(urlencode($id))?>>view</a>

------------------------------------------------------------------
view.php ³»¿ë

function decrypt($string,$key) {
$key = md5($key);
$td = mcrypt_module_open('des', '','cfb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = substr($string,0,$iv_size);
$string = substr($string,$iv_size);
if (mcrypt_generic_init($td, $key, $iv) != -1) {
$c_t = mdecrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $c_t;
}
}

echo decrypt($_REQUEST['id'],title);

Admin
Admin

°Ô½Ã¹° °¹¼ö : 380
Age : 54
Registration date : 2008-08-09

Character sheet
test:

https://study4u.forumkorean.com

À§·Î Go down

À§·Î


 
Permissions in this forum:
´ä±ÛÀ» ¿Ã¸± ¼ö ¾ø½À´Ï´Ù