请求url并获取加密文本


request url and get encrypted text

我在mysite中有缓存文件,我想从远程获取所有文件。我在我的网站上写了一个小应用程序,这个echos加密文本带有查询字符串。从远程获取文本可以,但文本有一些坏字符或其他错误。我的远程代码:

$req = file_get_contents($website.'Cache.php?cacheid='.$filename.'&action=getContent');
        $req = trim($req);
        $req = str_replace (array("'r'n", "'n", "'r"), '', $req);
        $decryptedText = decrypt(trim($req),'mypass') ;
    array_push($fileNameTexts,'<div style="color:red;">'.$filename.'</div><div>'.$decryptedText.'</div>');
}
$template->data['decryptedCaches'] = $fileNameTexts;   
}

 function decrypt($encrypted, $password, $salt='mysalt') {
     **file_put_contents(DIR_SYSTEM.'test'.'.txt',$encrypted );**
     $key = hash('SHA256', $salt . $password, true);
     $iv = base64_decode(substr($encrypted, 0, 22) . '==');
     $encrypted = substr($encrypted, 22);
     $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "'0'4");
     $hash = substr($decrypted, -32);
     $decrypted = substr($decrypted, 0, -32);
     if (md5($decrypted) != $hash) return false;
     return $decrypted;
}     

file_put_contents保存正确的数据,但不会返回真正的解密数据。

当我尝试时

$decryptedText = decrypt(trim('kjsfkdsjflkdsflksdjfsl'),'mypass') ;

它运行正常。我试着用trim和str_replace替换一些字符,但它不起作用。从请求返回的数据是否有任何错误字符?什么是问题?

您必须转换所有坏的字符,但base64不起作用。

解决方案:将字符串转换为十六进制。使用bin2hex($yourvalue)而不是base64_encode,并使用pack("H*" ,$string); 对此进行解密

我希望我的答案能对你有所帮助。