BBRSACryptor
使用OpenSSL进行公钥和私钥的加解密
以及私钥签名,公钥验签
添加到你的工程
pod 'BBRSACryptor'
如何加载密钥
从文件中读取密钥:
BBRSACryptor *cryptor = [[BBRSACryptor alloc] init];
NSData *keyData = [NSData dataWithContentsOfFile:keyPath];
[cryptor importRSAPublicKeyPEMData:keyData];
使用byte数组方式读入:
获取byte数组:
./rsatool read public.pem # rsatool 是Demo工程中的另一个target: rsatool 编译出的小工具
在代码中读取字节数组:
char keyBytes[] = {45,45,45,45,45,66,69,71,73,78,32,80,85,66,76,73,67,32,75,69,89,45,45,45,45,45,10,77,73,73,66,73,106,65,78,66,103,107,113,104,107,105,71,57,119,48,66,65,81,69,70,65,65,79,67,65,81,56,65,77,73,73,66,67,103,75,67,65,81,69,65,49,71,83,49,72,103,51,69,53,105,55,113,114,75,115,69,114,81,70,116,10,90,49,110,,49,118,80,84,85,101,79,113,107,117,74,110,99,105,115,86,53,121,101,89,104,75,10,83,83,66,107,67,114,65,88,114,105,52,81,76,110,121,85,57,87,73,57,80,70,115,76,89,119,109,82,121,109,102,102,104,121,73,57,97,108,106,107,77,108,55,112,122,82,115,105,117,51,72,117,50,52,47,68,79,97,99,78,103,80,83,121,10,115,119,73,68,65,81,65,66,10,45,45,45,45,45,69,78,68,32,80,85,66,76,73,67,32,75,69,89,45,45,45,45,45,10};
NSData *pemData = [NSData dataWithBytes:keyBytes length:sizeof(keyBytes)];
[rsaCryptor importRSAPublicKeyPEMData:pemData];