AES256 String encryption on PHP and decryption on iPhone

江枫思渺然 提交于 2019-12-02 03:47:59

问题


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);

and this one the 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


回答1:


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:

  • Difference in PHP encryption from iOS and .NET

  • AES Encrypt in C#, decrypt in PHP

  • DES Encryption in PHP and C#



来源:https://stackoverflow.com/questions/4455104/aes256-string-encryption-on-php-and-decryption-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!