iPhone/PHP 加密/解密中缺少某些内容
我一直在尝试在 iPhone 应用程序和 PHP Web 服务之间实现某种加密。然而它不起作用。看起来文本的前半部分没有解密,而后半部分则解密得很好。我应该怎么办?
PHP加密方法如下:
function decrypt($str, $iv) {
$iv .= "00000000";
$str = base64_decode($str);
return self::decrypt_data($str, $iv, self::secret_key);
}
加密文本的iPhone东西使用这样的CryptoHelper类:
NSString *encrypted = [[CryptoHelper sharedInstance] encryptString:dataString];
CryptoHelper类可以在 http://pastie.org/1267796。
I have been trying to implement some encryption between an iPhone app and a PHP web service. It's not working however. It seems like the first half of the text is NOT decrypted while the second half is decrypted just fine. What should I do?
The PHP encryption method is as follows:
function decrypt($str, $iv) {
$iv .= "00000000";
$str = base64_decode($str);
return self::decrypt_data($str, $iv, self::secret_key);
}
The iPhone stuff that encrypts the text uses a CryptoHelper class like this:
NSString *encrypted = [[CryptoHelper sharedInstance] encryptString:dataString];
The CryptoHelper class can be seen at http://pastie.org/1267796.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一个简单的示例,其中将已知的 Base64 编码字符串从 iPhone 应用程序发送到 PHP。
将已知的有效字符串与 PHP 获取的字符串进行比较。我知道最近,当尝试从脚本向 PHP 执行 Ajax post 时,我们遇到了一些字符(特别是
+
)被 PHP 转换为空格的问题,因为它自动进行 URL 解码。我们必须将所有+
切换为它们的%
(URL 编码的%2B
)等效项。这为我们解决了问题。Try a simple example where you send a known Base64 encoded string from the iPhone app to PHP.
Compare the known valid string to what PHP is getting. I know recently, when trying to do an Ajax post from a script to PHP, we were having trouble with some characters (specifically
+
) being converted to spaces by PHP because it was doing a URL decode automatically. We had to switch all+
to their%
(URL-encoded%2B
) equivalent. This fixed the problem for us.