开发者

RSA Encryption on iPhone

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 cons开发者_JAVA技巧truct 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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜