<legend id='ZMCay'><style id='ZMCay'><dir id='ZMCay'><q id='ZMCay'></q></dir></style></legend>
  • <small id='ZMCay'></small><noframes id='ZMCay'>

        • <bdo id='ZMCay'></bdo><ul id='ZMCay'></ul>
      1. <i id='ZMCay'><tr id='ZMCay'><dt id='ZMCay'><q id='ZMCay'><span id='ZMCay'><b id='ZMCay'><form id='ZMCay'><ins id='ZMCay'></ins><ul id='ZMCay'></ul><sub id='ZMCay'></sub></form><legend id='ZMCay'></legend><bdo id='ZMCay'><pre id='ZMCay'><center id='ZMCay'></center></pre></bdo></b><th id='ZMCay'></th></span></q></dt></tr></i><div id='ZMCay'><tfoot id='ZMCay'></tfoot><dl id='ZMCay'><fieldset id='ZMCay'></fieldset></dl></div>

        <tfoot id='ZMCay'></tfoot>
      2. iOS5和iOS6的CCCrypt区别

        时间:2023-05-30

            <tbody id='HM31G'></tbody>

          <small id='HM31G'></small><noframes id='HM31G'>

          <tfoot id='HM31G'></tfoot>
          • <i id='HM31G'><tr id='HM31G'><dt id='HM31G'><q id='HM31G'><span id='HM31G'><b id='HM31G'><form id='HM31G'><ins id='HM31G'></ins><ul id='HM31G'></ul><sub id='HM31G'></sub></form><legend id='HM31G'></legend><bdo id='HM31G'><pre id='HM31G'><center id='HM31G'></center></pre></bdo></b><th id='HM31G'></th></span></q></dt></tr></i><div id='HM31G'><tfoot id='HM31G'></tfoot><dl id='HM31G'><fieldset id='HM31G'></fieldset></dl></div>
                <bdo id='HM31G'></bdo><ul id='HM31G'></ul>
                <legend id='HM31G'><style id='HM31G'><dir id='HM31G'><q id='HM31G'></q></dir></style></legend>
                  本文介绍了iOS5和iOS6的CCCrypt区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个使用 CCCrypt() 的解密/加密方法,它在 iOS5 上运行得非常好.现在我正在使用 iOS6 SDK 并且从未更改过我的代码,但似乎有些东西坏了.我仍然可以使用密钥加密字符串并对其进行解密,但如果我使用另一个密钥解密同一字符串,则从 CCCrypt() 返回的 CCCryptStatus 仍然是 0(kCCSuccess) - 即使解密失败,因为在那之后我的 NSData 没有被填充.在 iOS5 上,我收到了我可以处理的错误消息 -4303.有什么想法现在有什么问题吗?

                  I have got a decryption/encryption method using CCCrypt() which worked really well on iOS5. Now I am working with the iOS6 SDK and never changed my code, but it seems that something is broken. I can still encrypt a string with a key and decrypt it, but if I use another key to decrypt the same string, the CCCryptStatus coming back from CCCrypt() is still 0(kCCSuccess) - even when the decryption fails, because after that my NSData isn't filled. On iOS5 I got the error message -4303 which I could handle then. Any ideas what can be wrong now?

                  我的代码:

                  char keyPtr[kCCKeySizeAES256+1]; 
                  bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
                  
                  // fetch key data
                  [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
                  
                  if (encryptOrDecrypt == kCCDecrypt)
                  {
                      data = [GTMBase64 decodeData:data];
                  }
                  
                  NSUInteger dataLength = [data length];
                  
                  size_t bufferSize = dataLength + kCCBlockSizeAES128;
                  
                  void *buffer = malloc(bufferSize);
                  
                  size_t numBytesDecrypted = 0;
                  CCCryptorStatus cryptStatus = CCCrypt(encryptOrDecrypt,
                                                        kCCAlgorithmAES128,
                                                        kCCOptionPKCS7Padding,
                                                        keyPtr,
                                                        kCCKeySizeAES256,
                                                        NULL ,
                                                        [data bytes], dataLength, 
                                                        buffer,       bufferSize, 
                                                        &numBytesDecrypted);
                  
                  if (cryptStatus != kCCSuccess){
                      // do something, but cryptStatus is always 0!
                  }
                  

                  在 iPad Simulator 5 上对其进行了测试.当我使用另一个密钥进行解密时,我收到的状态是 -4303.仅在 ios6 中返回的状态为 0.

                  Tested it on iPad Simulator 5. When I make a decryption with another key the status I receive is -4303. Only in ios6 the status coming back is 0.

                  推荐答案

                  我不是加密专家,但我有同样的问题并想出了一个解决方法,也许在有人找到真正的解决方案之前会很好.

                  I'm not an expert i encryption, but I have the same problem and figured a workaround maybe it will be fine until some will find a real solution.

                  我所做的只是确定哪个 iOS 正在运行,对于 6+,我将 CCCrypt 调用更改为无填充(0 表示无填充,1 是 kCCOptionPKCS7Padding 的枚举)

                  all I did is to figure which iOS is running and for 6+ i'm changing the CCCrypt call to no padding (0 is for no padding, 1 is the enum for kCCOptionPKCS7Padding)

                  float version = [[UIDevice currentDevice].systemVersion floatValue];
                  if (version >= 6)
                  {
                      CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0,
                                                            keyPtr, kCCKeySizeAES128,
                                                            ivPtr,
                                                            [self bytes], dataLength,
                                                            buffer, bufferSize, 
                                                            &numBytesDecrypted );
                  
                  
                      if( cryptStatus == kCCSuccess )
                      {
                          return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
                      }
                  
                      free( buffer ); 
                      return nil;
                  }
                  else
                  {
                      CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 1,
                                                            keyPtr, kCCKeySizeAES128,
                                                            ivPtr,
                                                            [self bytes], dataLength,
                                                            buffer, bufferSize, 
                                                            &numBytesDecrypted );
                      if( cryptStatus == kCCSuccess )
                      {
                          return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
                      }
                  
                      free( buffer );
                      return nil;
                  }
                  

                  这篇关于iOS5和iOS6的CCCrypt区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:应用程序崩溃 - “DiskImageCache:无法解析旧目录的 下一篇:iOS5.0.1 上的内存泄漏 drawInRect

                  相关文章

                  最新文章

                • <i id='zpDOw'><tr id='zpDOw'><dt id='zpDOw'><q id='zpDOw'><span id='zpDOw'><b id='zpDOw'><form id='zpDOw'><ins id='zpDOw'></ins><ul id='zpDOw'></ul><sub id='zpDOw'></sub></form><legend id='zpDOw'></legend><bdo id='zpDOw'><pre id='zpDOw'><center id='zpDOw'></center></pre></bdo></b><th id='zpDOw'></th></span></q></dt></tr></i><div id='zpDOw'><tfoot id='zpDOw'></tfoot><dl id='zpDOw'><fieldset id='zpDOw'></fieldset></dl></div>
                • <small id='zpDOw'></small><noframes id='zpDOw'>

                      <bdo id='zpDOw'></bdo><ul id='zpDOw'></ul>
                    <tfoot id='zpDOw'></tfoot><legend id='zpDOw'><style id='zpDOw'><dir id='zpDOw'><q id='zpDOw'></q></dir></style></legend>