1

根据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);
4

1 回答 1

5

您可能想查看Apple Developer Forums 上的此线程,并查看“CryptoExercise”示例代码。

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

于 2010-03-10T16:41:21.337 回答