#file that contains the encryption algorithms. #redirects user to main page if tries to access this one, informs them of it if header redirect does not work if($PHP_SELF == "crypt.php") { header("Location: index.php"); echo 'Access to page only granted through proper submittal of form data from the main page.'; exit; } #encrypts data using vars provided, vars preceded with '&' are passed by refrence function encrypt($cipher, $mode, &$key, &$rawData, &$iv) { #opens mcrypt module and prepares vars $encData = "Encryption Error!! Go back and try again."; #gets replaced upon successful encrypiton $cipher = strtolower($cipher); $mode = strtolower($mode); $td = mcrypt_module_open($cipher, '',$mode, ''); $ivSize = mcrypt_enc_get_iv_size($td); if($key == "") $key = "password"; $key = substr($key, 0, mcrypt_enc_get_key_size($td)); if($iv == "") { $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND); } elseif(strlen($iv) > $ivSize) { $iv = substr($iv, 0, $ivSize); } elseif(strlen($iv) < $ivSize) { $iv = str_pad($iv, $ivSize, 'x'); } #initialize encryption handle if (mcrypt_generic_init($td, $key, $iv) != -1) { #encrypt data $encData = mcrypt_generic($td, $rawData); #shutdown encryption mcrypt_generic_deinit($td); } mcrypt_module_close($td); return $encData; } #decrypts data using vars provided, vars preceded with '&' are passed by refrence function decrypt($cipher, $mode, &$key, &$encData, &$iv) { #opens mcrypt module and prepares vars $rawData = "Decryption Error!!"; #gets replaced upon successful decrypiton $cipher = strtolower($cipher); $mode = strtolower($mode); $td = mcrypt_module_open($cipher, '',$mode, ''); $ivSize = mcrypt_enc_get_iv_size($td); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); if(strlen($iv) > $ivSize) { $iv = substr($iv, 0, $ivSize); } elseif(strlen($iv) < $ivSize) { $iv = str_pad($iv, $ivSize, 'x'); } #initialize decryption handle if (mcrypt_generic_init($td, $key, $iv) != -1) { #decrypt data $rawData = rtrim(mdecrypt_generic($td, $encData), "\0"); #trim to remove padding #shutdown encryption mcrypt_generic_deinit($td); } mcrypt_module_close($td); return $rawData; } ?>
|
|
|||||||||||||||||||
Encrypt and Decrypt anything you like.•This system allows the user to encrypt, decrypt, and store ecrypted information online in a user-friendly format.
|
|
||||||||||||||||||
| Source written by Adam Ray. ©2004. All rights reserved. Version 1.0.4.0 | |||||||||||||||||||