响应式网站建设哪家公司好,房产中介公司网站源码,阳江网站制作建设,扬州高端网站建设在你的 iOS App中 使用 OpenSSL 库 转发 英文原文链接#xff1a;http://www.x2on.de/2010/07/13/tutorial-iphone-app-with-compiled-openssl-1-0-0a-library/下文有错误 参照有风险#xff1a;需要修改 输入命令行的部分 建议用英文原版里的#xff01;#xff01;#…在你的 iOS App中 使用 OpenSSL 库 转发 英文原文链接http://www.x2on.de/2010/07/13/tutorial-iphone-app-with-compiled-openssl-1-0-0a-library/下文有错误 参照有风险需要修改 输入命令行的部分 建议用英文原版里的在你的 iOS App中 使用 OpenSSL 库——译自x2on的“Tutorial: iPhone Appwith compiled OpenSSL 1.0.0a Library”原文地址http://www.x2on.de/2010/07/13/tutorial-iphone-app-with-compiled-openssl-1-0-0a-library/本文有少许地方做了调整。1、下载OpenSSL源代码库http://www.openssl.org/source/当前最新版本1.0.0d。下载后将其中的 openssl-1.0.0x 目录解压出来放在合适的地方。2、编译OpenSSLopenssl是一个c语言函数库为方便在Xcode中使用我们需要把它编译为静态库。打开crypto/ui/ui_openssl.c进行编辑。将static volatile sig_atomic_t intr_signal;修改为static volatile int intr_signal;否则会出现一个编译错误。2.1 编译 i386 库用于iPhone模拟器执行以下命令mkdir ssllibs 将在用户主目录下建立ssllibs目录。切换到openssl-1.0.0a安装解压目录在其下建立3个子目录cd openssl-1.0.0a mkdir openssl_armv6 openssl_armv7 openssl_i386 执行目录下的congfigure./configure BSD-generic32--openssldir/Users/username/openssl-1.0.0a/openssl_i386编辑 makefile 文件找到CC gcc修改为CC/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386下一行在CFLAG 的后面增加-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk进行编译make make install检查 openssl_i386/lib目录下 libcrypto.a和 libssl.a 是否生成。2.2 编译 armv6 库armv6架构的iOS使用先将编译好的 i386 库保存到 ssllibs 目录mv openssl_i386 ../ssllibs 清除上次编译的配置make clean执行configure重新生成新的编译配置./configure BSD-generic32--openssldir/Users/username/openssl-1.0.0a/openssl_armv6修改 makefile 文件将 CCgcc修改为CC /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-arch armv6注意这里是iPhoneOS.platform而不是先前的 iPhoneSimulator.platform了。同样需要在CFLAG后面加上-isysroot/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk可以进行编译了makemake install检查 openssl_armv6/lib 目录下 libcrypto.a和 libssl.a 是否生成。2.3 编译 armv7 库armv7 架构的 iOS 使用先将先前编译好的 armv6 库移到 ssllibs 目录。mv openssl_armv6 ../ssllibs 清除前面编译配置make clean执行configure配置编译环境./configure BSD-generic32 --openssldir/Users/username/openssl-1.0.0a/openssl_armv7修改 makefile 文件将 CCcc修改为CC /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-arch armv7注意gcc 编译选项 arch 由 armv6 变为了 armv7。同时在CFLAG后面添加-isysroot/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk进行编译make make install检查 openssl_armv7/lib 目录下 libcrypto.a和 libssl.a 是否生成。把编译结果移到ssllibs目录mv openssl_armv7 ../ssllibs2.4 制作“通用”静态库通用静态库是一个“多架构”文件它是多个单一架构静态库的融合。制作“通用”静态库需要使用 Mac OS X 的 lipo 命令具体请参考Mac OS X 手册。合并 libcrypto.a 库lipo -create../ssllibs/openssl_i386/lib/libcrypto.a../ssllibs/openssl_armv6/lib/libcrypto.a ../ssllibs/openssl_armv7/lib/libcrypto.a-output ../ssllibs/libcrypto.a 合并 libssl.a 库lipo -create ../ssllibs/openssl_i386/lib/libssl.a../ssllibs/openssl_armv6/lib/libssl.a ../ssllibs/openssl_armv7/lib/libssl.a-output ../ssllibs/libssl.a3、在 Xcode 项目的进行设置把 OpenSSL 的 include 目录拷贝到项目文件夹。把 libcrypto.a 和 libssl.a 文件拷贝到项目文件夹。把 libcrypto.a 和 libssl.a 文件拖到项目的Framework 组中。在 target 上右键选择 Get Info将 LibrarySearch Path 设置为$(inherited) “$(SRCROOT)”将 User Header Search Paths 设为include。选中 Always Search User Paths 选项。现在可以在你的iPhone项目中实用OpenSSL了。4、写一个应用 OpenSSL 的小例子新建 Window-based application命名为OpenSSLTest.“AddàExisting FrameworksàOthers…”把libssl.a和libcrypto.a加进来即我们前面制作的“通用”库。打开项目info 的 Build 设置在 HeaderSearch Paths 中加入 OpenSSL 的头文件路径,如/Users/yourname/Library/openssl-1.0.0a/include注意勾上“Recursive”搜索子目录。接下来写点简单的代码。为求省事我们把所有代码写在main.m里#import UIKit/UIKit.h#include Openssl/md5.hvoidMd5(NSString*);intmain(intargc, char*argv[]) {NSAutoreleasePool* pool [[NSAutoreleasePoolalloc] init];Md5(12345);intretVal UIApplicationMain(argc, argv, nil, nil);[pool release];returnretVal;}voidMd5(NSString* string){// 输入参数1要生成md5值的字符串NSString--uchar*unsignedchar*inStrg (unsignedchar*)[[string dataUsingEncoding:NSASCIIStringEncoding] bytes];// 输入参数2字符串长度unsignedlonglngth [string length];// 输出参数3要返回的md5值MD5_DIGEST_LENGTH为16bytes128 bitsunsignedcharresult[MD5_DIGEST_LENGTH];// 临时NSString变量用于把uchar* 组装成可以显示的字符串2 个字符一byte 的16 进制数NSMutableString*outStrg [NSMutableStringstring];// 调用OpenSSL 函数MD5(inStrg,lngth, result);unsignedinti;for(i 0; i MD5_DIGEST_LENGTH; i){[outStrg appendFormat:%02x, result];}NSLog(inputstring:%,string);NSLog(md5:%,outStrg);}你可以在控制台查看程序的输出inputstring:12345md5:827ccb0eea8a706c4c34a16891f84e7b 下文仅供参考并不实用 http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/ Easy inclusion of OpenSSL into iOS projects Oddly, iOS doesn’t provide any OpenSSL implementation at all — If you want to do anything with crypto (like checking signatures, checksumming, etc.), you have to build in the library yourself. I came across a great XCode project wrapper for OpenSSL yesterday, by Stephen Lombardo. This is an XCode project file that contains a target to build OpenSSL from source, and works with both Mac and iOS projects. I made some modifications to it, in order to make it work by just dropping in the OpenSSL source tarball, without having to dirty up your source tree with the extracted OpenSSL distribution. Here’s how to use it: Download the OpenSSL source.Put the downloaded OpenSSL source tar.gz into the same folder as openssl.xcodeproj (I put it in Library/openssl within my project tree).Drag the openssl.xcodeproj file into your main project tree in XCode.Right-click on your project target, and add openssl.xcodeproj under “Direct Dependencies” on the General tab. On the Build tab for your project’s target, find the “Header Search Paths” option, and add the path: $(SRCROOT)/Library/openssl/build/openssl.build/openssl/include (Assuming you’ve put openssl.xcodeproj at the path Library/openssl — adjust as necessary). Expand your target’s “Link Binary With Libraries” build stage, and drag libcrypto.a from the openssl.xcodeproj group.Then, you can just import and use as normal (#import openssl/dsa.h, etc). Download it here