00001 <?php 00003 00010 00011 00016 class SCrypter 00017 { 00018 private $encryptkey, $td, $iv, $ks, $filterkey; 00020 00023 function setKey($key) 00024 { 00025 srand(1); 00026 $this->encryptkey = $key; 00027 $this->td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CFB, ''); 00028 $this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND); 00029 $this->ks = mcrypt_enc_get_key_size($this->td); 00030 $this->filterkey = substr(sha1($key), 0, $this->ks); 00031 } 00033 function encrypt($data) 00034 { 00035 $this->setKey($this->encryptkey); 00036 mcrypt_generic_init($this->td, $this->filterkey, $this->iv); 00037 $cipher = mcrypt_generic($this->td, $data); 00038 mcrypt_generic_deinit($this->td); 00039 mcrypt_module_close($this->td); 00040 srand(uniqid()); 00041 return $cipher; 00042 } 00044 function decrypt($data) 00045 { 00046 $this->setKey($this->encryptkey); 00047 mcrypt_generic_init($this->td, $this->filterkey, $this->iv); 00048 $deciphered = mdecrypt_generic($this->td, $data); 00049 mcrypt_generic_deinit($this->td); 00050 mcrypt_module_close($this->td); 00051 srand(uniqid()); 00052 return $deciphered; 00053 } 00054 } 00055 00056 00057 ?>