up. 双向数据加密

This commit is contained in:
u2nyakim 2025-08-29 15:59:53 +08:00
parent 29bf079731
commit 11a226c417

View File

@ -23,8 +23,8 @@ class ContextMiddleware extends middleware
if ($request->header('x-encrypted') == 'true') {
$encryptedData = $request->param('encryptedData','');
if($encryptedData) {
$jsonData = $this->decryptCryptoJSData($encryptedData);
$request->withPost($jsonData);
$jsonInput = $this->decryptCryptoJSData($encryptedData);
$request->withInput($jsonInput);
}
}
@ -161,7 +161,7 @@ class ContextMiddleware extends middleware
* @return array 解密后的数据
* @throws ValidateException 解密失败时抛出异常
*/
private function decryptCryptoJSData(string $encryptedData): array
private function decryptCryptoJSData(string $encryptedData): string
{
// Base64解码
$data = base64_decode($encryptedData);
@ -188,7 +188,7 @@ class ContextMiddleware extends middleware
OPENSSL_RAW_DATA,
$iv
);
return json_decode($decrypted, true);
return $decrypted;
}
private function evpBytesToKey($salt): array