AES256 PHP上的字符串加密和iPhone上的解密 [英] AES256 String encryption on PHP and decryption on iPhone

查看:114
本文介绍了AES256 PHP上的字符串加密和iPhone上的解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个我的PHP代码:

i have this on my php code:

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "bla";
$text = json_encode($rows);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv)
print base64_encode($crypttext);

这一个iphone:

NSString *response = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.bla.com/myinfo.php"]  encoding:NSUTF8StringEncoding error:&error];
    response = [[NSData base64DataFromString:response] AESDecryptWithPassphrase:@"bla"];
    response = [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] autorelease];
    NSLog(response);

但它不起作用,任何人都可以使用一种方法?

谢谢

but it doesn't work, anyone has a method that works?
thanks

推荐答案

我敢打赌,你绊倒了一个填补问题。我在三个SO答案中解决了这个问题,所以您可能会在其中一个答案中找到解决方案:

I bet, you're stumbling upon a padding issue. I addressed this topic in three SO answers, so you likely find the solution in one of those answers:

AES加密C#,解密PHP

DES加密在PHP和C#

这篇关于AES256 PHP上的字符串加密和iPhone上的解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆