RSA - 2

上篇多多少少科普了一下RSA的一些相关内容

现在来讲解一下在iOS上怎么使用它,iOS开发的话,相信大家都会对这两个库非常熟悉:

libcrypto、libssl,而用C写的openssl库就是用了这里面很多东西,相信接入早期的支付宝SDK的人都会了解。


上面这都是小小铺垫哈,我们在GitHub上打iOS RSA,看到星星最多的几个,我们可以下载,会发现有这样一段代码:



可以看到,上篇所导出的pem 公钥、密钥都是明文写在这里。一来这非常不专业,二来不安全,三来最要命的是,当前这个RSA类是引用:Security库,如果你换一对密钥,公钥,会大概率出现,无法解密的情况(上篇所说的不能直接对私钥直接使用)!


那我们只能另辟蹊径,看看能不能读取pem文件的内容,而不是硬编码了。

我已经将它放在GitHub上,可以参考一下:

https://github.com/iosfighterlb/RSA-Openssl


一定要注意:

1.公钥秘钥换行符也是一部分,如果字符串的话需要用转义\n



别的话,也是非常好理解,下一篇章我们会继续iOS在RSA上的使用!


RSA-Tool 2 Copyright ?2000-2002 by tE! [TMG] Introduction Please read this text carefully. This utility has been made for those who want to use the RSA public key algorithm in their own programs. It offers creation of strong keypairs and a nice integer factorization feature which makes use of several differnt factoring methods including the MPQS. It's possible to factor integers +256 bits in size but please keep in mind that this can take a *lot* of memory and time ! Thus it's not recommended to try factoring bigger numbers on slow machines with a few MB of physical Memory. Don't even think of trying to factor 512 bit numbers for example.. RSA-Tool 2 Features: - Secure keypair generation - Key test dialog - Support of multiple number bases - Auto base-conversion on select - Support of numbers up to 4096 Bits 1. About RSA RSA is a Public Key Cryptosystem developed in 1977 by Ronald Rivest, Adi Shamir and Leonard Adleman. Since 09-20-2000 the U.S. Patent #4,405,829 on this Algorithm EXPIRED! That means that the Algorithm is Public Domain now and can be used by everyone for free, even in commercial software. 2. Parameters P = 1st large prime number Q = 2nd large prime number (sizes of P and Q should not differ too much!) E = Public Exponent (a random number which must fulfil: GCD(E, (P-1)*(Q-1))==1) N = Public Modulus, the product of P and Q: N=P*Q D = Private Exponent: D=E^(-1) mod ((P-1)*(Q-1)) Parameters N and E are public whereas D is -private- and must NEVER be published! P and Q are not longer needed after keygeneration and should be destroyed. To obtain D from the public key (N, E) one needs to try splitting N in its both prime factors P and Q. For a large Modulus N (512 bit and more) with carefully chosen primefactors P and Q this is a very difficult problem. All the security of the RSA encryption scheme relies on that integer factorization problem (tough there's no mathematical proof for it). To fin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值