1

我对此很陌生。我的 PHP 回声返回垃圾。我认为我缺少一个编码步骤。

我的 OBJ-C 代码

NSString *key = @"12345678901234561234567890123456";

    //main path for account login PHP file
    NSString *accountURL = [NSString stringWithFormat:configManager.accountURL, username, password];

    //convert password to data and encrypt
    NSData *crypt = [[[password stringValue]dataUsingEncoding:NSUTF8StringEncoding]AES256EncryptWithKey:key];

    NSString *variables = [NSString stringWithFormat:@"?username=%@&access=%@&page=%ld",[username stringValue], crypt, [sender tag]];

    // get rid of spaces in encoded URL
    NSString *niceURLString = [variables stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    //tack niceURL on to end of base URL
    NSString *goToURL = [accountURL stringByAppendingString:niceURLString];
    NSLog(@"%@", goToURL);

    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:goToURL]];

PHP

$upswd = $_GET['access'];
    $key = "12345678901234561234567890123456";
$upswd = trim($upswd, "<>"); //remove these brackets from url

$result = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $upswd, 'ecb');
//$result = utf8_decode($result);
echo ($result);
4

1 回答 1

0
        mcrypt_create_iv(
            mcrypt_get_iv_size(
                MCRYPT_RIJNDAEL_256,
                MCRYPT_MODE_ECB
            )

您正在创建一个新的 IV,您需要使用原始 IV。它通常与加密文本一起传递,由分隔符分隔,常用的分隔符是。或 | 然后,您让 PHP 在分隔符处拆分加密字符串,使用 IV 作为解密函数,并将另一部分用作加密数据。

于 2012-11-19T00:29:44.510 回答