我编写了一个iOS应用程序来与现有的服务器进行通信。服务器生成RSA密钥对(公钥和私钥),并向客户端发送公钥。
客户端( iOS应用程序)只能使用公钥进行加密,并将加密后的数据发送给服务器。
所以,我需要一个目标C函数来进行RSA加密。
输入:
过程:
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;输出:
uwGuSdCgDxAAN3M5THMrNcec3Fm/Kn+uUk7ty1s70oH0FNTAWz/7FMnEjWZYOtHe37G3D4DjqiWijyUCbRFaz43oVDUfkenj70NWm3tPZcpH8nsWYevc9a1M9GbnNF2jRlami8LLUTZiogypSVUuhcJvBZBOfea9cOonX6BG+vw=
问题:
如何实现这一功能?
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;我已经有很长时间的digg了,上面还有谷歌和苹果的文件。我发现苹果需要一个.der文件来进行加密,而不仅仅是公钥。
发布于 2015-02-03 05:02:10
我会回答我的问题:
1.使用公钥字符串创建SecKeyRef
我得到了这篇文章的帮助:http://blog.flirble.org/2011/01/05/rsa-public-key-openssl-ios/#its-all-in-the-format
它导致了我的代码:https://github.com/ideawu/Objective-C-RSA/blob/master/RSA.m#L34
2.使用SecKeyRef加密输入数据
使用苹果的SecKeyEncrypt(https://developer.apple.com/library/ios/documentation/Security/Reference/certifkeytrustservices/index.html)
3. github的完整代码
发布于 2021-11-06 08:32:20
1:https://github.com/Kitura/Swift-JWT 2:https://github.com/TakeScoop/SwiftyRSA 3:https://github.com/soyersoyer/SwCrypt 4:https://github.com/Kitura/BlueRSA
欲了解更多信息,请访问苹果官方文档https://developer.apple.com/documentation/security链接
https://stackoverflow.com/questions/28291609
复制相似问题