【问题标题】:RSA Encryption on iPhoneiPhone 上的 RSA 加密
【发布时间】:2011-01-25 23:25:27
【问题描述】:

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

【问题讨论】:

    标签: iphone cryptography rsa keychain cryptoapi


    【解决方案1】:

    您可能想查看 Apple 开发者论坛上的 this thread,并查看“CryptoExercise”示例代码。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-20
      • 1970-01-01
      • 2013-03-12
      • 2014-08-16
      • 2014-06-29
      • 1970-01-01
      • 2012-11-26
      • 2015-03-16
      相关资源
      最近更新 更多