在你的 iOS App中 使用 OpenSSL 库 转发

在你的 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 = [[NSAutoreleasePoolallocinit];
Md5(@"12345");
intretVal = UIApplicationMain(argc, argv, nilnil);
[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_LENGTH16bytes128 bits
unsignedcharresult[MD5_DIGEST_LENGTH];
// 临时NSString变量,用于把uchar* 组装成可以显示的字符串:个字符一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

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/267078.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

elastic search java_在 Java 应用程序中使用 Elasticsearch

如果您使用过 Apache Lucene 或 Apache Solr&#xff0c;就会知道它们的使用体验非常有趣。尤其在您需要扩展基于 Lucene 或 Solr 的解决方案时&#xff0c;您就会了解 Elasticsearch 项目背后的动机。Elasticsearch(构建于 Lucene 之上)在一个容易管理的包中提供了高性能的全文…

PostgreSQL增强版命令行客户端(pgcli)

效果&#xff1a; 安装&#xff1a; https://www.pgcli.com/install 官网&#xff1a; https://www.pgcli.com/ 转载于:https://www.cnblogs.com/EasonJim/p/9042418.html

网络设备的注册与初始化

2019独角兽企业重金招聘Python工程师标准>>> NIC可用之前&#xff0c;其相关联的net_device数据结构必须先初始化&#xff0c;添加到内核网络设备数据库、配置并开启。不要把注册/除名以及开启/关闭混淆是十分重要的&#xff0c;这是两种不同的概念&#xff1a; 如果…

java jdbc reparecall_Java Connection.prepareCall方法代碼示例

本文整理匯總了Java中java.sql.Connection.prepareCall方法的典型用法代碼示例。如果您正苦於以下問題&#xff1a;Java Connection.prepareCall方法的具體用法&#xff1f;Java Connection.prepareCall怎麽用&#xff1f;Java Connection.prepareCall使用的例子&#xff1f;那…

Vue提供操作DOM的方法

<div ref"wrapper"> Vue.js 提供了我们一个获取 DOM 对象的接口—— vm.$refs。在这里&#xff0c;我们通过了 this.$refs.wrapper访问到了这个 DOM 对象&#xff0c;并且我们在 mounted 这个钩子函数里&#xff0c;this.$nextTick 的回调函数中初始化 因为 V…

[转]敏捷开发中编写高质量Java代码

本文转自&#xff1a;http://dev.yesky.com/103/11164603.shtml 敏捷开发的理念已经流行了很长的时间&#xff0c;在敏捷开发中的开发迭代阶段中&#xff0c;我们可以通过五个步骤&#xff0c;来有效的提高整个项目的代码质量。 Java项目开发过程中&#xff0c;由于开发人员的…

java静态成员方法_java的静态成员、静态方法的注意事项!

在JAVA中&#xff0c;存在内部类和外部类&#xff0c;如果出现有static时&#xff0c;大家应注意&#xff1a;1、 静态内部类不能直接访问外部类的非静态成员&#xff0c;但可以通过new 外部类().成员 的方式访问2、 如果外部类的静态成员与内部类的成员名称相同&#xff0c;可…

php实现姓名按首字母排序的类与方法

php将名字按首字母进行排序 <?php public function getFirstChar($s){$s0 mb_substr($s,0,3); //获取名字的姓$s iconv(UTF-8,gb2312, $s0); //将UTF-8转换成GB2312编码//dump($s0);if (ord($s0)>128) { //汉字开头&#xff0c;汉字没有以U、V开头的$ascord($s{0})*25…

ios3怎么取消长按弹出菜单_苹果:iOS13取消3D-Touch重压改为长按只是个BUG~

原标题&#xff1a;苹果&#xff1a;iOS13取消3D-Touch重压改为长按只是个BUG~目前iOS 13中3D-Touch功能在桌面级菜单采用的是类似iPhone XR的触觉感应(Haptic touch)&#xff0c;用户只需要长按App图标即可呼出菜单&#xff0c;继续长按则会出现删除应用的抖动界面。不同于以往…

设△ABC的内角A,B,C,所对的边分别为a,b,c,且acosB-bcosA=3/5c,则tan(A-B)的最大值为

设△ABC的内角A,B,C,所对的边分别为a,b,c,且acosB-bcosA3/5c,则tan(A-B)的最大值为 转载于:https://www.cnblogs.com/Mary-Sue/p/9048289.html

BGP笔记1

1、BGP属于EGP&#xff0c;是高级DV协议&#xff0c;也被称为路径矢量协议&#xff0c;基于TCP 179端口。 2、现在使用版本BGP-4。 3、第一次做完整更新&#xff0c;以后就只增量更新 4、Autonomous Systems&#xff1a;运行同一种选路策略&#xff0c;由统一管理者管理。 1&am…

java 打包下载文件_java下载打包下载文件

一&#xff1a;对于文件的一些操作1.创建文件夹private String CreateFile(String dir) {File file new File(dir);if (!file.exists()) {//创建文件夹boolean mkdir file.mkdir();} else {}return dir;}2.复制文件private void copyFile(File source, File dest) throws IOE…

也说读书

记得当年毕业前夕&#xff0c;一位教授说&#xff1a;“希望你们毕业后&#xff0c;能坚持每年读10本书。”当时不以为然&#xff0c;区区十本&#xff0c;岂非小菜&#xff01;毕业后&#xff0c;迫于生计&#xff0c;东奔西走&#xff0c;很难静心读书&#xff0c;偶尔拿起书…

C# 巧用anchor和dock设计复杂界面(控件随着窗体大小的变化而变化)【转】

这个在做winform程序的空间编程的时候遇到过太多次了&#xff0c;自己也想留下点经验&#xff0c;搜索了一下&#xff0c;这篇文章很好很强大了&#xff0c;感谢博主“驴子的菜园”。 程序界面如上 各部分简要说明&#xff1a; 整个窗体上覆盖一个splitcontainer。 splitcontai…

修改java启动参数_如何修改jvm启动参数

用java命令查看。用java -option进行修改参数。还有tomcat&#xff0c;eclipse启动时通过配置文件加载的。详细如下&#xff1a;安装Java开发软件时&#xff0c;默认安装包含两个文件夹&#xff0c;一个JDK(Java开发工具箱)&#xff0c;一个JRE(Java运行环境&#xff0c;内含JV…

非常完善的Log4net详细说明(转)

最可能来源&#xff1a;https://blog.csdn.net/ydm19891101/article/details/50561638 其它转载者&#xff1a;http://www.cnblogs.com/zhangchenliang/p/4546352.html 1、概述 log4net是.Net下一个非常优秀的开源日志记录组件。log4net记录日志的功能非常强大。它可以将日志分…

话说招聘面试

最近公司有一个新项目&#xff0c;是一个软件和硬件结合的项目&#xff0c;具体的就是一个cs软件通过485通信操作硬件的基站&#xff0c;基站上面挂着传感器和其他设备&#xff0c; 当然我只负责软件也就是上位机部分。通过1个月多的时间&#xff0c;每天开会开会调研调研&…

mysql内链接与交叉连接_SQLServer 2008中的交叉连接与内部连接

这里是交叉连接和内部连接的最佳示例。考虑下表表&#xff1a;Teacherx------------------------x| TchrId | TeacherName |x----------|-------------x| T1 | Mary || T2 | Jim |x------------------------x表&#xff1a;Studentx-------------…

获得数据库中表字段的名字.txt

获得数据库中所有数据库的名字&#xff1a;select name From sysdatabases 获得某个数据库中所有表的名字&#xff1a;select name from sysobjects where typeU获得某个表中字段的名字&#xff1a;select name from syscolumns where idobject_id(表名)use masterif exists(S…

java pause_java – 更有效的暂停循环方式

可用的工具是&#xff1a;等待/通知 – 我们都试图摆脱这个古老的系统.信号量 – 一旦你的线程抓住它,你持有它直到释放,所以再次抓住它不会阻止.这意味着您无法在自己的线程中暂停.CyclicBarrier – 每次使用时都必须重新创建.ReadWriteLock – 我的最爱.您可以让任意多个线程…