在PHP上解密后,在PHP(AES,CBC)中加密,空值

时间:2012-08-08 12:53:24

标签: php iphone encryption mcrypt

我在PHP中加密一个值,另一个程序员正在iPhone应用程序中解密它。我们都不会被称为加密知识。根据我在本网站和其他地方发现的信息,一切看起来都是正确的。 iPhone的人说他从解密过程中获得了成功的返回码,但是数据的空值。

以下是PHP方面:

$key = getproperty("cryptkey","testkeytobechanged");
srand();
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22) return false;
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, md5($key), $iv_base64."::::".$authority->get_mobiuser()->get_message(), MCRYPT_MODE_CBC, $iv));
$rv = $iv_base64.$encrypted;

这就是iPhone方面的内容:

   //We have compared the hex values after base64 decoding enough that I am satisfied there is not an issue at that point.

   NSString *b = [[dict objectForKey:@"data"]objectForKey:@"nlbal"];
   NSData *iv = [NSData dataFromBase64String:[[b substringToIndex:22]stringByAppendingString:@"=="]];
   NSLog(@"IV %@", [iv description]);
   NSString *e = [b substringFromIndex:22];
   NSData *encrypted = [NSData dataFromBase64String:e];
   NSLog(@"ENC %@", encrypted);
   NSUInteger dataLength = [encrypted length];
   uint8_t unencryptedData[dataLength + kCCKeySizeAES128];
   size_t unencryptedLength;
   //NSData *un = [encrypted AES128DecryptWithKey:[SessionManager md5:@"testkeytobechanged"] iv:iv];



   //From my research, I understand this to be the correct form to match the encryption I use on the PHP side
   CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, 
                                          kCCAlgorithmAES128, 0, 
                                          [[SessionManager md5:@"testkeytobechanged"]UTF8String], 
                                          kCCKeySizeAES128, [iv bytes], 
                                          [encrypted bytes], dataLength, 
                                          unencryptedData, dataLength, &unencryptedLength);

   NSString *output = [[NSString alloc] initWithBytes:unencryptedData length:unencryptedLength encoding:NSUTF8StringEncoding];
   // output = [[NSString alloc]initWithData:un encoding:NSUTF8StringEncoding];
   //NSLog(@"un %@", [un description]);
   NSLog(@"OUTPUT %i %@", cryptStatus, output);

正如我上面所说,这段代码显然会生成一个成功代码,但是它的值为空。

0 个答案:

没有答案