话不多说直接来。
https://github.com/x2on/OpenSSL-for-iPhone下载下来后打开终端cd到这个目录,直接./build-libssl.sh运行脚本。
等待个几分钟,当看到
Build library for iOS…
Build library for tvOS…
Done
这里我们就编译好需要的静态文件了,这里不得不感谢大神做的贡献.
把这两个.a和include拖入项目中,然后设置Header Search paths,文件手动拖入进去就会生成路径了,接下来撸代码。
RSA
@interface RSAEn : NSObject
int init();
int public_encrypt_to_hex(const char* src, int strlength, char* dest);
int private_decrypt_from_hex(const char* src, int srcLength, char* dest);
@end
#import "RSAEn.h"
#include "rsa.h"
#include "pem.h"
#include "aes.h"
#include "ssl.h"
@implementation RSAEn
enum RSA_KEY_TYPE
{
RSA_PUBLIC_KEY = 0,
RSA_PRIVATE_KEY = 1
};
RSA* rsa_public;
RSA* rsa_private;
RSA* create_rsa_from_file(const char *file_name, int k_type)
{
FILE *fp = fopen(file_name, "rb");
if (fp == NULL)
{
printf("file [%s] open failed!\n", file_name);
}
RSA *rsa = RSA_new();
if (k_type == RSA_PUBLIC_KEY)