JS 解密 Laravel 加密字符串

shu*_*132 0 javascript php encryption laravel

我必须laravel 6用 JavaScript 解密加密的字符串。输入 laravel.env文件

APP_KEY=base64:Rva4FZFTACUe94+k+opcvMdTfr9X5OTfzK3KJHIoXyQ=
Run Code Online (Sandbox Code Playgroud)

并且在config/app.php文件密码中设置为以下...

APP_KEY=base64:Rva4FZFTACUe94+k+opcvMdTfr9X5OTfzK3KJHIoXyQ=
Run Code Online (Sandbox Code Playgroud)

到目前为止我所尝试过的如下......

Laravel 代码

'cipher' => 'AES-256-CBC',
Run Code Online (Sandbox Code Playgroud)

HTML 和 JavaScript 代码

$test = 'this is test';
$encrypted = Crypt::encrypt($test);
Run Code Online (Sandbox Code Playgroud)

上述代码的控制台输出如下屏幕截图所示...

在此输入图像描述

我已经尝试了来自谷歌和堆栈溢出的许多其他 JS 代码,但没有运气。

更新

这是在单独的离线系统中解密字符串的要求。我不会在实时网站上使用 javascript 进行加密。相反,用java脚本解密将在离线系统上完成。

mad*_*oet 7

这是使用 AES-256-CBC 作为密码解密使用 Laravel 编码的 javascript 文本的方法。

\n

使用 CryptoJS 4.0...

\n
// Created using Crypt::encryptString(\'Hello world.\') on Laravel.\n// If Crypt::encrypt is used the value is PHP serialized so you\'ll \n// need to "unserialize" it in JS at the end.\nvar encrypted = \'eyJpdiI6ImRIN3QvRGh5UjhQNVM4Q3lnN21JNFE9PSIsInZhbHVlIjoiYlEvNzQzMnpVZ1dTdG9ETTROdnkyUT09IiwibWFjIjoiM2I4YTg5ZmNhOTgyMzgxYjcyNjY4ZGFkNTc4MDdiZTcyOTIyZjRkY2M5MTM5NTBjMmMyZGMyNTNkMzMwYzY3OCJ9\';\n\n// The APP_KEY in .env file. Note that it is base64 encoded binary\nvar key = \'E2nRP0COW2ohd23+iAW4Xzpk3mFFiPuC8/G2PLPiYDg=\';\n\n// Laravel creates a JSON to store iv, value and a mac and base64 encodes it.\n// So let\'s base64 decode the string to get them.\nencrypted = atob(encrypted);\nencrypted = JSON.parse(encrypted);\n\nconsole.log(\'Laravel encryption result\', encrypted);\n\n\n\n// IV is base64 encoded in Laravel, expected as word array in cryptojs\nconst iv = CryptoJS.enc.Base64.parse(encrypted.iv);\n\n// Value (chipher text) is also base64 encoded in Laravel, same in cryptojs\nconst value = encrypted.value;\n\n\n// Key is base64 encoded in Laravel, word array expected in cryptojs\nkey = CryptoJS.enc.Base64.parse(key);\n\n// Decrypt the value, providing the IV. \nvar decrypted = CryptoJS.AES.decrypt(value, key, {\n  iv: iv\n});\n\n// CryptoJS returns a word array which can be \n// converted to string like this\ndecrypted = decrypted.toString(CryptoJS.enc.Utf8);\n\nconsole.log(decrypted); // Voil\xc3\xa0! Prints "Hello world!"\n\n
Run Code Online (Sandbox Code Playgroud)\n