在你的 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、编译OpenSSL
openssl是一个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 文件,将 CC=gcc修改为:
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

可以进行编译了:
make
make 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 文件,将 CC=cc修改为:
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 ../ssllibs

2.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.a

3、在 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.h>
voidMd5(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为16bytes,128 bits
unsignedcharresult[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:12345
md5: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:

  1. Download the OpenSSL source.
  2. Put the downloaded OpenSSL source tar.gz into the same folder as openssl.xcodeproj (I put it in Library/openssl within my project tree).
  3. Drag the openssl.xcodeproj file into your main project tree in XCode.
  4. Right-click on your project target, and add openssl.xcodeproj under “Direct Dependencies” on the General tab.
  5. 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).

  6. 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

 

在你的 iOS App中 使用 OpenSSL 库 转发相关推荐

  1. php图片涂鸦,IOS_详解iOS App中图片的线段涂鸦功能的添加方法,接下来我们要讲图片的涂鸦, - phpStudy...

    详解iOS App中图片的线段涂鸦功能的添加方法 接下来我们要讲图片的涂鸦,我们分开一点一点拓展,先给图片上划线 创建项目 起名testAddLine 接下来我们在默认生成的ViewControlle ...

  2. 在Facebook iOS app中减少FOOMs

    最近在看FOOM,翻译一下facebook的解决方案. 原文链接在Facebook iOS app中减少FOOMs 在Facebook iOS app中减少FOOMs 在Facebook,我们致力于使 ...

  3. 快速获取iOS APP中的所有素材

    2019独角兽企业重金招聘Python工程师标准>>> 1.我们都知道最常规的获取app中的素材是通过iTunes下载应用 -> 右键show in Finder获取ipa文件 ...

  4. 苹果官方要求在iOS App中提供帐户删除选项

    背景情况 最近发布iOS应用到市场时,在审核阶段被官方打回. 查看原因惊讶地发现,审核团队竟然说缺少账号删除功能? 经过一番百度搜索后,才发现官方又有新的审核政策,那就是要求在2022年6月30号之后 ...

  5. iOS app中不能跳转到商店更新

    文章目录 问题:跳转没有反应 延申说明 问题:跳转没有反应 如果app在苹果商店中的访问地址中带有中文,直接使用带中文url是跳转不成功的,需要对这个带中文的url进行UrlEncode编码才能正常跳 ...

  6. clion中链接openssl库

    错误显示 前提条件 apt-get install openssl apt-get install openssl-dev 解决办法 在CMakeLists.txt文件中加入如下命令 link_lib ...

  7. iOS APP中嵌入网速监测功能

    企鹅的手机管家.一些网页都提供了网速监测功能.在开发过程中我们偶尔也需要开发这个模块,以提示用户网速的状况,增强用户体验. 常见的网络测速方案 通过调研发现,目前常见的网络测速方案只有两种: 方案1: ...

  8. ios html 全屏播放,iOS APP 中H5视频默认全屏播放问题解决

    问题描述:在Android中,视频可以正常在H5页面局部播放,iOS中则自动切换至全屏模式. 查看资料得以解决,20190301记录下来. 解决方法:IOS10及以后,在 video标签页中只包含 w ...

  9. iOS APP 中H5视频默认全屏播放

    问题描述:在Android中,视频可以正常在H5页面局部播放,iOS中则自动切换至全屏模式,需要禁止视频自动全屏播放. 解决方法: H5端: iOS10以上H5视频不自动全屏播放识别 playsinl ...

最新文章

  1. LinkExtractor
  2. Codeforces 930 A. Peculiar apple-tree (dfs)
  3. 深入理解计算机系统:进程
  4. Android 4.X 系统加载 so 失败的原因分析
  5. web前端面试问答_Web服务面试问答
  6. K8S的SDN容器网络解决方案【机制篇】
  7. 保护 WordPress 安全的10个方法
  8. Android NDK开发(1)----- Java与C互相调用实例详解
  9. JSP标签,jsp:include,jsp:forward用法介绍及示例
  10. gp数据库运维:远程登录 杀进程
  11. 东北大学软件项目管理与过程改进题库——首字母排序
  12. ItemCF的Python实现
  13. ubuntu离线中文语音识别
  14. Pytorch节省显存、加速训练的小技巧
  15. mysql修改索引语句_mysql——创建索引、修改索引、删除索引的命令语句
  16. Idea打字变成繁体
  17. 织梦网站 mysql,织梦(DEDECMS)网站程序及数据库迁移搬家教程
  18. 模块化:ES Module与commonJS
  19. Google的两种广告推广方式
  20. at91sam9x5ek linux 4,为AT91SAM9X5-EK开发板建立linux目标文件

热门文章

  1. bzoj4403:序列统计
  2. 线程的基本协作和生产者消费者
  3. 20162317 2017-2018-1 《程序设计与数据结构》第8周学习总结
  4. cocos2d-x 帧动画
  5. 写给在Java和.net中徘徊的新手
  6. kylinH5框架之项目开发调试
  7. 黑白两客进入页面(1)
  8. sublime text3安装js提示的插件
  9. WordPress Mail Subscribe List插件‘sml_name’参数HTML注入漏洞
  10. 【转载】网络流和最小费用流