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

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

    1. <tfoot id='7H6Dj'></tfoot>
      • <bdo id='7H6Dj'></bdo><ul id='7H6Dj'></ul>

      1. 如何将base64字符串解码/转换为NSData?

        时间:2024-04-14
        • <bdo id='S9C4x'></bdo><ul id='S9C4x'></ul>
                <legend id='S9C4x'><style id='S9C4x'><dir id='S9C4x'><q id='S9C4x'></q></dir></style></legend>

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

                  <tbody id='S9C4x'></tbody>

                  本文介绍了如何将base64字符串解码/转换为NSData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您好,我想弄清楚如何将 iOS 应用程序中的 base64 字符串转换/解码为 NSData,以便我可以解密我加密的数据.

                  Hello I am trying to figure out how convert / decode a base64 string in an iOS application to NSData, so I can decrypt the data that I encrypted.

                  我用于将 NSData 转换为 base 64 字符串的方法可以在 这里找到类似的方法创建将base 64字符串解码/转换为NSData的方法?

                  The method I used for converting the NSData to a base 64 string can be found here Is there a similar way to create method to decode / convert the base 64 string to NSData?

                  推荐答案

                  这就是我要找的.

                  This is what I was looking for.

                  + (NSData *)base64DataFromString: (NSString *)string
                  {
                  unsigned long ixtext, lentext;
                  unsigned char ch, inbuf[4], outbuf[3];
                  short i, ixinbuf;
                  Boolean flignore, flendtext = false;
                  const unsigned char *tempcstring;
                  NSMutableData *theData;
                  
                  if (string == nil)
                  {
                      return [NSData data];
                  }
                  
                  ixtext = 0;
                  
                  tempcstring = (const unsigned char *)[string UTF8String];
                  
                  lentext = [string length];
                  
                  theData = [NSMutableData dataWithCapacity: lentext];
                  
                  ixinbuf = 0;
                  
                  while (true)
                  {
                      if (ixtext >= lentext)
                      {
                          break;
                      }
                  
                      ch = tempcstring [ixtext++];
                  
                      flignore = false;
                  
                      if ((ch >= 'A') && (ch <= 'Z'))
                      {
                          ch = ch - 'A';
                      }
                      else if ((ch >= 'a') && (ch <= 'z'))
                      {
                          ch = ch - 'a' + 26;
                      }
                      else if ((ch >= '0') && (ch <= '9'))
                      {
                          ch = ch - '0' + 52;
                      }
                      else if (ch == '+')
                      {
                          ch = 62;
                      }
                      else if (ch == '=')
                      {
                          flendtext = true;
                      }
                      else if (ch == '/')
                      {
                          ch = 63;
                      }
                      else
                      {
                          flignore = true; 
                      }
                  
                      if (!flignore)
                      {
                          short ctcharsinbuf = 3;
                          Boolean flbreak = false;
                  
                          if (flendtext)
                          {
                              if (ixinbuf == 0)
                              {
                                  break;
                              }
                  
                              if ((ixinbuf == 1) || (ixinbuf == 2))
                              {
                                  ctcharsinbuf = 1;
                              }
                              else
                              {
                                  ctcharsinbuf = 2;
                              }
                  
                              ixinbuf = 3;
                  
                              flbreak = true;
                          }
                  
                          inbuf [ixinbuf++] = ch;
                  
                          if (ixinbuf == 4)
                          {
                              ixinbuf = 0;
                  
                              outbuf[0] = (inbuf[0] << 2) | ((inbuf[1] & 0x30) >> 4);
                              outbuf[1] = ((inbuf[1] & 0x0F) << 4) | ((inbuf[2] & 0x3C) >> 2);
                              outbuf[2] = ((inbuf[2] & 0x03) << 6) | (inbuf[3] & 0x3F);
                  
                              for (i = 0; i < ctcharsinbuf; i++)
                              {
                                  [theData appendBytes: &outbuf[i] length: 1];
                              }
                          }
                  
                          if (flbreak)
                          {
                              break;
                          }
                      }
                  }
                  
                  return theData;
                  }
                  

                  这篇关于如何将base64字符串解码/转换为NSData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 NSData 创建 base-64 字符串 下一篇:错误的 base-64 错误

                  相关文章

                  1. <small id='ZX8wY'></small><noframes id='ZX8wY'>

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

                        <bdo id='ZX8wY'></bdo><ul id='ZX8wY'></ul>