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

      1. 如何在 Cocoa/Objective-C 中将文件编码和解码为 Base64

        时间:2024-04-14
          <bdo id='RjQW1'></bdo><ul id='RjQW1'></ul>

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

                  <legend id='RjQW1'><style id='RjQW1'><dir id='RjQW1'><q id='RjQW1'></q></dir></style></legend><tfoot id='RjQW1'></tfoot>

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

                  本文介绍了如何在 Cocoa/Objective-C 中将文件编码和解码为 Base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在尝试让一个小型肥皂客户端工作,其中包括在请求的 xml 中发送证书文件.

                  I am currently trying to get a small soap client to work, which includes to send a certificate file within the xml of the request.

                  我可以毫不费力地将文件转换为 NSData 对象 - 但是我必须将其转换为一些 Base64 字符串.环境是Mac OSX,Xcode 4.3.

                  I have no trouble getting the file into an NSData object - but then I have to convert it to some Base64 String. Environment is Mac OSX, Xcode 4.3.

                  我发现很多较早的帖子都在处理这个问题 - 但我发现最好的是一些使用 OpenSSL 库的代码,其中包含大量已弃用的方法.

                  I have found a lot of older posting dealing with that - but the best I found was some code that made use of OpenSSL libs and where containing loads of deprecated methods.

                  所以,我的问题如下:有没有比使用 OpenSSL 库更好的方法?如果有,您是否有一些 URL 或更新的代码片段?

                  So, my question is as follows: Is there a better way than to use the OpenSSL libs? If yes, do you perchance have some URL or more recent code scraps?

                  如果不是,我想有一些可以推荐的处理 Base64 的项目.毕竟 Base64 并不少见.

                  If no, I guess there is some project out there which deals with Base64 that can be recommended. After all Base64 is not that uncommon.

                  感谢您的帮助!

                  推荐答案

                  这是使用 CommonCrypto 完成的 base64 编码:

                  Here is a base64 encoding done with CommonCrypto:

                  很简单的代码,归类也不难

                  it is very easy code, it would not be difficult to put it in a category

                  如果您将其添加到您的项目中,您还需要添加 Security.framework

                  if you add this to your project you need also to add the Security.framework

                  #include <CoreFoundation/CoreFoundation.h>
                  #include <Security/Security.h>
                  
                  static NSData *base64helper(NSData *input, SecTransformRef transform)
                  {
                      NSData *output = nil;
                  
                      if (!transform)
                          return nil;
                  
                      if (SecTransformSetAttribute(transform, kSecTransformInputAttributeName, input, NULL))
                          output = (NSData *)SecTransformExecute(transform, NULL);
                  
                      CFRelease(transform);
                  
                      return [output autorelease];
                  }
                  
                  NSString *base64enc(NSData *input)
                  {
                      SecTransformRef transform = SecEncodeTransformCreate(kSecBase64Encoding, NULL);
                  
                      return [[[NSString alloc] initWithData:base64helper(input, transform) encoding:NSASCIIStringEncoding] autorelease];
                  }
                  
                  NSData *base64dec(NSString *input)
                  {
                      SecTransformRef transform = SecDecodeTransformCreate(kSecBase64Encoding, NULL);
                  
                      return base64helper([input dataUsingEncoding:NSASCIIStringEncoding], transform);
                  }
                  

                  这篇关于如何在 Cocoa/Objective-C 中将文件编码和解码为 Base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将 zlib 压缩的 base 64 字符串覆盖到 Uiimage 中的问题 下一篇:如何使用 base64 字符串制作 PDF 文件?迅速

                  相关文章

                      <bdo id='29fKV'></bdo><ul id='29fKV'></ul>

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

                      <small id='29fKV'></small><noframes id='29fKV'>

                      <legend id='29fKV'><style id='29fKV'><dir id='29fKV'><q id='29fKV'></q></dir></style></legend>
                    1. <tfoot id='29fKV'></tfoot>