<?phpheader('Content-Type: text/html; charset=iso-8859-9');class SifreleCoz {var $anahtar;var $veri;var $td;var $iv;var $bas = false;function SifreleCoz($anahtar='',$veri=''){if ($anahtar != ''){$this->bas($anahtar);}$this->veri = $veri;}function bas(&$anahtar){$this->td = mcrypt_module_open ('des', '', 'ecb', '');$this->anahtar = substr ($anahtar, 0, mcrypt_enc_get_key_size($this->td));$iv_boyut = mcrypt_enc_get_iv_size($this->td);$this->iv = mcrypt_create_iv($iv_boyut, MCRYPT_RAND);$this->bas = true;}function anahtarAyarla($anahtar){$this->bas($anahtar);}function veriAyarla($veri){$this->veri = $veri;}function &anahtarGetir(){return $this->anahtar;}function &veriGetir(){return $this->veri;}function &sifrele($veri=''){return $this->_sifre('sifrele',$veri);}function &coz($veri=''){return $this->_sifre('coz',$veri);}function kapat(){mcrypt_module_close($this->td);}function &_sifre($mode,&$veri){if ($veri != ''){$this->veri = $veri;}if ($this->bas){if (mcrypt_generic_init($this->td,$this->anahtar,$this->iv) != -1){if ($mode == 'sifrele'){$this->veri = mcrypt_generic($this->td, $this->veri);}elseif($mode == 'coz'){$this->veri = mdecrypt_generic($this->td, $this->veri);}mcrypt_generic_deinit($this->td);return $this->veri;}else{trigger_error('Error basialising '.$mode.'ion handle',E_USER_ERROR);}}else{trigger_error('Key not set. Use anahtarAyarla() method',E_USER_ERROR);}}}$sc = new SifreleCoz('gizli anahtar');$kullanici = 'kullanici';$sifre = 'sifre';$s_kullanici = $sc->sifrele($kullanici);$s_sifre = $sc->sifrele($sifre);echo 'sifreli kullanici: '.$s_kullanici;echo '<br>';echo 'sifreli sifre: '.$s_sifre;echo '<br>';echo 'sifresiz kullanici: '.$sc->coz($s_kullanici);echo '<br>';echo 'sifresiz sifre: '.$sc->coz($s_sifre);echo '<br>';$sc->kapat();?>
Çıktısı
sifreli kullanici: £ÈÄN·/©„İ·ÂÒ·ñ£·sifreli sifre: rt·ï§ğsifresiz kullanici: kullanicisifresiz sifre: sifre