Skip to content

Instantly share code, notes, and snippets.

@wwwjsw
Created March 22, 2017 13:15
Show Gist options
  • Select an option

  • Save wwwjsw/01f49405adc74e57e766e462bc4a5902 to your computer and use it in GitHub Desktop.

Select an option

Save wwwjsw/01f49405adc74e57e766e462bc4a5902 to your computer and use it in GitHub Desktop.
function encrypt($key, $plain_text) {
$plain_text = trim($plain_text);
$iv = substr(md5($key), 0, mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB));
$c_t = mcrypt_cfb(MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
return trim(chop(base64_encode($c_t)));
}
function decrypt($key, $c_t) {
$c_t = trim(chop(base64_decode($c_t)));
$iv = substr(md5($key), 0, mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB));
$p_t = mcrypt_cfb(MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
return trim(chop($p_t));
}
$pass_safe = 'A567E343HD7438CE342A';
$minha_string = 'user'
echo encrypt($pass_safe, $minha_string) .'<br/>';
echo decrypt($pass_safe, encrypt($pass_safe, $minha_string)) .'<br/><br/>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment