rsa加密的解决方案都是需要证书或者文件的,
对于服务端提供了公钥,没有给证书或者pem文件的rsa加密:
把公钥和你需要编码得Nsstring都转换成NSData
用rsa公钥 编码你所需要编码得内容 最后转换成Nsstring
//库 SecKeyWrapper
//RSA加密
- (NSString *)encryptWithString:(NSString *)content
{
NSData *publicKey = [NSData dataFromBase64String:@"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtkjDEKiKBvg7ps9Cvv1mt2gfnm"];
NSData *usernamm = [content dataUsingEncoding: NSUTF8StringEncoding];
NSData *newKey= [SecKeyWrapper encrypt:usernamm publicKey:publicKey];
NSString *result = [newKey base64EncodedString];
return result;
}