|
function encrypt($string)
{
$applicationConfig = DI::make("config");
$cc_encryption_hash = $applicationConfig["cc_encryption_hash"];
$key = md5(md5($cc_encryption_hash)) . md5($cc_encryption_hash);
$hash_key = _hash($key);
$hash_length = strlen($hash_key);
$iv = _generate_iv();
$out = "";
for( $c = 0; $c < $hash_length; $c++ )
{
$out .= chr(ord($iv[$c]) ^ ord($hash_key[$c]));
}
$key = $iv;
for( $c = 0; $c < strlen($string); $c++ )
{
if( $c != 0 && $c % $hash_length == 0 )
{
$key = _hash($key . substr($string, $c - $hash_length, $hash_length));
}
$out .= chr(ord($key[$c % $hash_length]) ^ ord($string[$c]));
}
return base64_encode($out);
}
function decrypt($string)
{
$applicationConfig = DI::make("config");
$cc_encryption_hash = $applicationConfig["cc_encryption_hash"];
$key = md5(md5($cc_encryption_hash)) . md5($cc_encryption_hash);
$hash_key = _hash($key);
$hash_length = strlen($hash_key);
$string = base64_decode($string);
$tmp_iv = substr($string, 0, $hash_length);
$string = substr($string, $hash_length, strlen($string) - $hash_length);
$iv = "";
$out = "";
for( $c = 0; $c < $hash_length; $c++ )
{
$ivValue = (isset($tmp_iv[$c]) ? $tmp_iv[$c] : "");
$hashValue = (isset($hash_key[$c]) ? $hash_key[$c] : "");
$iv .= chr(ord($ivValue) ^ ord($hashValue));
}
$key = $iv;
for( $c = 0; $c < strlen($string); $c++ )
{
if( $c != 0 && $c % $hash_length == 0 )
{
$key = _hash($key . substr($out, $c - $hash_length, $hash_length));
}
$out .= chr(ord($key[$c % $hash_length]) ^ ord($string[$c]));
}
return $out;
}
有大佬了解么? |
|