Skip to content

Instantly share code, notes, and snippets.

@thobroni
Created June 3, 2020 12:27
Show Gist options
  • Select an option

  • Save thobroni/bc66c56975b9425c30775e9d59471448 to your computer and use it in GitHub Desktop.

Select an option

Save thobroni/bc66c56975b9425c30775e9d59471448 to your computer and use it in GitHub Desktop.
<?php
function get_encrypt($string, $key)
{
srand((double) microtime() * 1000000);
$key = md5($key);
$td = mcrypt_module_open("des", "", "cfb", "");
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
if (mcrypt_generic_init($td, $key, $iv) != -1)
{
$c_t = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$c_t = $iv . $c_t;
return $c_t;
}
}
function get_decrypt($string, $key)
{
$key = md5($key);
$td = mcrypt_module_open("des", "", "cfb", "");
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = substr($string, 0, $iv_size);
$string = substr($string, $iv_size);
if (mcrypt_generic_init($td, $key, $iv) != -1)
{
$c_t = mdecrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $c_t;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment