javascript 使用PHP进行javascript atob操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16626535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:24:10  来源:igfitidea点击:

JavaScript atob operation using PHP

phpjavascriptencryption

提问by blasteralfred Ψ

I would like to know if it is possible to decrypt the JavaScript encrypted text (which is encrypted using JavaScript's btoa function), using PHP.

我想知道是否可以使用 PHP 解密 JavaScript 加密文本(使用 JavaScript 的 btoa 函数加密)。

回答by Sirko

Have a look at base64_decode().

看看base64_decode()

JavaScripts btoa()just encodes a string using Base64. The PHP functions for that are base64_encode()and base64_decode().

JavaScriptbtoa()只是使用Base64对字符串进行编码。PHP 函数是base64_encode()base64_decode()

回答by Baji

When I use window.btoa(String) to encode (not encrypt)text and send it over to the server side via AJAX, I find that the client-server exchange has resulted in plus signs ('+'), in the encoded text, being replaced by spaces (' ').

当我使用 window.btoa(String)编码(不加密)文本并通过 AJAX 将其发送到服务器端时,我发现客户端-服务器交换在编码文本中产生了加号 ('+') , 被空格 (' ') 替换。

To get the text back to proper encoding in PHP, I've had to use string transform like so:

为了让文本恢复到 PHP 中的正确编码,我不得不像这样使用字符串转换:

$clean = strtr( $_POST['ajax-text'], ' ', '+');
$ascii = base64_decode( $clean );