RSA加密在iPhone上 [英] RSA Encryption on iPhone

查看:399
本文介绍了RSA加密在iPhone上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据有关 http://forums.macrumors.com/showthread.php的讨论?t = 551476 下面看到的代码将用于RSA加密。密钥的数据类型(public)是SecKeyRef。我不会使用钥匙串,虽然,因为我只对加密的关键是公共的,没有秘密感兴趣。是否甚至可以使用crypto API然后?我目前的想法是从我的公钥构造一个SecKeyRef结构,并使用API​​。我不知道如何声明结构,虽然。有人知道吗?

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);


推荐答案

您可能需要查看此线程,并查看CryptoExercise示例代码。

You probably want to look at this thread on the Apple Developer Forums, and also check out the "CryptoExercise" sample code.

简而言之,建议您将公钥分发为DER编码的X.509证书,因为iPhone具有使用该格式的良好工具。您将使用SecCertificateCreateWithData读取DER编码的证书,然后使用SecTrustCopyPublicKey获取SecKeyRef。

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.

这篇关于RSA加密在iPhone上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆