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

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

        <tfoot id='nFbhr'></tfoot>
      2. 如何在 ECB 模式下使用 DES 加密 Objective C 中的 NSString?

        How to encrypt an NSString in Objective C with DES in ECB-Mode?(如何在 ECB 模式下使用 DES 加密 Objective C 中的 NSString?)
        <tfoot id='HUCgT'></tfoot>
          <tbody id='HUCgT'></tbody>

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

            • <small id='HUCgT'></small><noframes id='HUCgT'>

                <bdo id='HUCgT'></bdo><ul id='HUCgT'></ul>
                • 本文介绍了如何在 ECB 模式下使用 DES 加密 Objective C 中的 NSString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 iPhone 上的 Objective C 中加密一个 NSString.至少当我编码 "us=foo;pw=bar;pwAlg=false;" 时,我不想得到像 "TmsbDaNG64lI8wC6NLhXOGvfu2IjLGuEwc0CzoSHnrs=" 这样的字符串通过使用这个键:testtest".

                  I am trying to encrypt an NSString in Objective C on the iPhone. At least I wan't to get a string like "TmsbDaNG64lI8wC6NLhXOGvfu2IjLGuEwc0CzoSHnrs=" when I encode "us=foo;pw=bar;pwAlg=false;" by using this key: "testtest".

                  我现在的问题是,CCCrypt 总是返回4300 - 参数错误",我不知道为什么.

                  My problem for now is, that CCCrypt always returns "4300 - Parameter error" and I have no more idea why.

                  这是我的代码(5 小时 google 和 try'n'error 的结果):

                  This is my code (the result of 5 hours google and try'n'error):

                  NSString *token = @"us=foo;pw=bar;pwAlg=false;";
                  NSString *key = @"testtest";
                  
                  const void *vplainText;
                  size_t plainTextBufferSize;
                  
                  plainTextBufferSize = [token length];
                  vplainText = (const void *) [token UTF8String];
                  
                  CCCryptorStatus ccStatus;
                  uint8_t *bufferPtr = NULL;
                  size_t bufferPtrSize = 0;
                  size_t *movedBytes;
                  
                  bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
                  bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
                  memset((void *)bufferPtr, 0x0, bufferPtrSize);
                  // memset((void *) iv, 0x0, (size_t) sizeof(iv));
                  
                  
                  NSString *initVec = @"init Vec";
                  const void *vkey = (const void *) [key UTF8String];
                  const void *vinitVec = (const void *) [initVec UTF8String];
                  
                  ccStatus = CCCrypt(kCCEncrypt,
                                     kCCAlgorithmDES,
                                     kCCOptionECBMode,
                                     vkey, //"123456789012345678901234", //key
                                     kCCKeySizeDES,
                                     NULL,// vinitVec, //"init Vec", //iv,
                                     vplainText, //"Your Name", //plainText,
                                     plainTextBufferSize,
                                     (void *)bufferPtr,
                                     bufferPtrSize,
                                     movedBytes);
                  
                  NSString *result;
                  NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];
                  result = [myData base64Encoding];
                  

                  推荐答案

                  ECB 模式下的 DES 加密使用 8 字节的块大小,并单独对每个块进行编码.问题是您的输入字符串没有平均分成 8 个字节,并且密码器不知道如何处理最终的非 8 字节块.

                  DES encryption in ECB mode uses an 8 byte block size, and encodes each blocks individually. The problem is that your input string doesn't divide into 8 bytes equally and the cryptor doesn't know what to do with the final non 8 byte block.

                  修复方法是允许密码器通过将 kCCOptionPKCS7Padding 添加到 CCCrypt 的选项来填充最终块.例如(来自 NSData 加密类别的片段):

                  The fix is to allow the cryptor to pad the final block by adding kCCOptionPKCS7Padding to the options to CCCrypt. eg (snippet from an NSData encryption category):

                  CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, 
                                                        kCCAlgorithmDES, 
                                                        kCCOptionPKCS7Padding | kCCOptionECBMode,
                                                        keyPtr, 
                                                        kCCKeySizeDES,
                                                        NULL, 
                                                        [self bytes], 
                                                        dataLength,
                                                        buffer, 
                                                        bufferSize
                                                        &numBytesEncrypted);
                  

                  查看此帖子,了解有关填充算法的更多详细信息.希望这会有所帮助.

                  Take a look at this post for more details regarding padding algorithms. Hope this helps.

                  这篇关于如何在 ECB 模式下使用 DES 加密 Objective C 中的 NSString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  WebKit on th iPhone: is it possible to copy text to the clipboad with JavaScript(iPhone上的WebKit:是否可以使用JavaScript将文本复制到剪贴板)
                  When compiling for multiple targets in XCode, how do i ensure that certain files will not be included one target(在 XCode 中为多个目标编译时,我如何确保某些文件不会包含在一个目标中)
                  Selecting text in mobile Safari on iPhone(在 iPhone 上的移动 Safari 中选择文本)
                  Draggable UIImageView Partially Transparent amp; Irregular Shaped(可拖动的 UIImageView 部分透明 amp;不规则形状)
                  How to set the resolution of a saved image from the UIImagePickerController(如何从 UIImagePickerController 设置保存图像的分辨率)
                  objective - C : Loading image from URL?(目标 - C:从 URL 加载图像?)

                        1. <legend id='tM7Tr'><style id='tM7Tr'><dir id='tM7Tr'><q id='tM7Tr'></q></dir></style></legend>

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

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