Skip to content

Instantly share code, notes, and snippets.

@ahmetgungor
Created July 29, 2019 13:36
Show Gist options
  • Save ahmetgungor/8b615371f22fea2981d15234dd33fa46 to your computer and use it in GitHub Desktop.
Save ahmetgungor/8b615371f22fea2981d15234dd33fa46 to your computer and use it in GitHub Desktop.
sifrele
class sifrele {
protected $key;
protected $etype;
protected $mcmod;
protected $rand;
protected $iv;
public function __construct()
{
$this->etype = MCRYPT_RIJNDAEL_256;
$this->mcmod = MCRYPT_MODE_ECB;
$this->rand = MCRYPT_RAND;
$this->key = 'mnbnpg3l_Fuke2QD^V*4n-&NgsAVBeTy';
$this->iv = @mcrypt_create_iv(@mcrypt_get_iv_size($this->etype, $this->mcmod), $this->rand);
if(!function_exists('mcrypt_create_iv'))
{
exit('<strong>Hata:</strong> Mcrypt Kutuphanesi kur yoksa calismaz.');
}
if(version_compare(PHP_VERSION, '5.3.0') === -1)
{
exit('<strong>Hata:</strong> En Düşük php versiyonu PHP 5.3.0 olmalı .');
}
}
public function make($password, $key = FALSE)
{
return trim(bin2hex(mcrypt_encrypt($this->etype, $this->key($key), $password, $this->mcmod, $this->iv)));
}
public function take($protected, $key = FALSE)
{
return trim(mcrypt_decrypt($this->etype, $this->key($key), @hex2bin($protected), $this->mcmod, $this->iv));
}
public function key($key)
{
return strlen($key) == 32 ? $key : $this->key;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment