iOS 使用OpenSSL库
国外的大神已经搞了一个动态编译好的脚本git地址为:https://github.com/x2on/OpenSSL-for-iPhone
按照 工程的readme执行编译即可
编译完会生成 include和lib文件夹
include文件夹是头文件,lib是静态库,把这两个文件夹拖进项目
将include文件夹拖到Build Settings-> Header Search Paths 目录下
即可。
生成RSA私钥
openssl genrsa -out rsa_private_key.pem 1024
生成RSA公钥
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
查看公钥 内容
cat rsa_public_key.pem
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMlzbHqx2ScPEFvEHoTtBsPqYH
C48G6gzrJHjJFOL574S5nOK3Gwp3dmg5GCk1bHX29Mn5pUOxgjp0s33soglz52xv
kz9YvickCE6LWORnehg2xLbfXxclTD0Y6/nvyaFfcS1xyCKeOcxpnsUNzOVB7njg
pA6nVBE9Y7i21Dz4LwIDAQAB
-----END PUBLIC KEY-----
查看私钥 内容
cat rsa_private_key.pem
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDMlzbHqx2ScPEFvEHoTtBsPqYHC48G6gzrJHjJFOL574S5nOK3
Gwp3dmg5GCk1bHX29Mn5pUOxgjp0s33soglz52xvkz9YvickCE6LWORnehg2xLbf
XxclTD0Y6/nvyaFfcS1xyCKeOcxpnsUNzOVB7njgpA6nVBE9Y7i21Dz4LwIDAQAB
AoGAX6QtAqh2uZe8xM6eDOiTPJcI7HA126icg2xYXsA531deN5skzS6B9RjQXihy
Uzwx5VHH/cGJZLkZdKbYLkANpGBBwRDM8EYm10Dvr+jBw5IRynQxinHb28TW4OdA
cV2lI5KabLAvmqVWBF2lyhnVdROSs76SA+bVdivV5aFuAUECQQDosBApMqj1xniX
yo01XPjuBqScY8pVvAMc9WK5bqAQL9d+HudwQkk1QyeqM76i2jC9WecQVbQOCUiY
/arXeMIPAkEA4RaFnOMKSOplkbsXx4Q4bWQdVWvisnxEkDyXlrH6N7a5eiFOKtGc
Qr2I4hMe0fE01F9Lyd7qZHobM5jEWXQH4QJBAIWTfNOJp4Df3J6WwpVdt/E8kwbM
Kn0pH0hifbghj3V7YWOfbhD9nHUdBgopBkkKpGwuzfyMln5wSeK5zHdBdXUCQQCR
5thrDpxPEWkPIrhSQrmU5u1AvrLuwTBsUmpsaydnT9FAgjA5/y8L7/G3oW875N86
vh7RVuaWhLP3KRI1bcnhAkEA06Myw/PVr/TR6bASeocgWUf5dzmKB+w4px1bQcBL
BjdQWa2KeyWYHutDOUTEKJUNf9X8Q+sY+Y3/W28GQ0IKJQ==
-----END RSA PRIVATE KEY-----
http://www.jianshu.com/p/fc1103c99f28
https://github.com/ideawu/Objective-C-RSA
https://github.com/liuyuning/QuickRSA
http://tool.chacuo.net/cryptrsaprikey
http://www.cnblogs.com/littleatp/p/5878763.html
http://johnny.logdown.com/posts/69881-rsa-encryption-method-on-ios