iPhone 上的 RSA 加密
根据 http://forums.macrumors.com/showthread.php?t= 的讨论551476 下面看到的代码适用于 RSA 加密。密钥(“public”)的数据类型是 SecKeyRef。不过,我不会使用钥匙串,因为我只对密钥公开且不秘密的加密感兴趣。那么是否可以使用加密 API 呢?我当前的想法是仅从我的公钥构造一个 SecKeyRef 结构并使用 API。但我不知道该结构是如何声明的。有谁知道吗?您认为我的方法可行吗?
uint8_t *pPlainText = (uint8_t*) "This is a test";
uint8_t aCipherText[1024];
size_t iCipherLength = 1024;
status = SecKeyEncrypt(public,
kSecPaddingNone,
pPlainText,
strlen((char*) pPlainText ) + 1,
aCipherText,
&iCipherLength);
According the discussion on http://forums.macrumors.com/showthread.php?t=551476 the code seen below would do for RSA encryption. The datatype of the key ("public") is SecKeyRef. I will not be using the keychain, though, as I'm only interested in encryption where the key is public and is no secret. Is it even possible to use the crypto API then? My current idea is to construct a SecKeyRef struct from my public key only and use the API. I don't know how the struct is declared, though. Does anyone know? Do you think my approach will work?
uint8_t *pPlainText = (uint8_t*) "This is a test";
uint8_t aCipherText[1024];
size_t iCipherLength = 1024;
status = SecKeyEncrypt(public,
kSecPaddingNone,
pPlainText,
strlen((char*) pPlainText ) + 1,
aCipherText,
&iCipherLength);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想查看 Apple 开发者论坛上的此帖子,并查看“ CryptoExercise”示例代码。
简而言之,建议您将公钥作为 DER 编码的 X.509 证书进行分发,因为 iPhone 具有处理该格式的良好工具。您将使用 SecCertificateCreateWithData 读取 DER 编码的证书,然后使用 SecTrustCopyPublicKey 获取 SecKeyRef。
You probably want to look at this thread on the Apple Developer Forums, and also check out the "CryptoExercise" sample code.
In short, the recommendation is that you distribute your public key as a DER-encoded X.509 certificate, because the iPhone has good tools for working with that format. You would use SecCertificateCreateWithData to read in the DER-encoded certificate, then SecTrustCopyPublicKey to get the SecKeyRef.