RSA加密

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;

}

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0