• <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

        How to encode and decode Files as Base64 in Cocoa / Objective-C(如何在 Cocoa/Objective-C 中将文件编码和解码为 Base64)
          <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Difference between retain and copy?(保留和复制的区别?)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  What is the difference between quot;copyquot; and quot;retainquot;?(“复制和“复制有什么区别?和“保留?)
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)

                      <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'>

                            <tbody id='29fKV'></tbody>

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