我对此很新。我的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);
答案 0 :(得分:0)
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
)
您正在创建一个新IV,您需要使用原始IV。它通常与加密文本一起传递,分隔符由常用的分隔符分隔。或者然后你让PHP在分隔符处拆分加密的字符串,使用IV作为解密函数,并使用另一部分作为加密数据。