我有2个PHP页面,其中第1页加密字符串onLoad
,加密的字符串将通过URL传递到第2页。
偶尔(大约8个中的第2个)第2页无法解密字符串,并向我显示以下错误消息: failed to base64 decode the input ...
以下是我正在使用的内容:
AES-128-CBC
openssl_random_pseudo_bytes(16);
以下是一些其他信息:
有什么建议吗?
答案 0 :(得分:3)
要在网址中加入字符串,您需要URL encode它。对于base 64,您需要将=
替换为%3D
,但不要这样做。而是在URL中包含字符串时使用proper URL encoding function。
答案 1 :(得分:1)
感谢@Simba&的评论。 @David Schwartz,这里应该做些什么:
第1页:
- encrypt the string via openssl_encrypt();
- encode the encrypted string for sending via url by rawurlencode();
- concatenate those "encrypted+encoded" strings and send via url;
第2页:
- take the var out from $_GET;
- decode the var via rawurldecode();
- decrypt the decoded var via openssl_decrypt();
现在正常工作〜再次〜