Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,811
5,721
Isla Nublar
Hi guys,

First, let me say I already checked stack overflow and Apples documentation. Theres a ton of information and I'm not sure how to weed through it all.

All I need to do is use RSA encryption to encrypt a string (no decrypting). What would I use to do that in iOS that does not require a 3rd party library. (A 3rd party library is not an option).

I've heard mixed from Security.h framework (which the documentation for just doesn't exist, Xcode doesn't even find it), to a feature in Keychain lets you do it, to "it's impossible". I just can't find a concrete way or example how to do this.

Does anyone have any suggestions or could you steer me in the right direction on what to use?
 
Where are you getting the public key from? Are you going to generate your keys or get it from another source?

Apple has the CommonCrypto API that can do RSA but it's not very convenient to import a public key from an outside source. (In my case it was a .net server public key).

I ended up using openssl to import the public key and rsa encrypt.
Also at the time I coded this in 2011 CommonCrypto didn't support the padding option that was being used on the server and openssl did.

A quick google turned up an example of RSA encryption using CommonCrypto.

https://launchkey.com/docs/api/encryption/objective-c/commoncrypto#encrypt

Hope this helps.
 
Where are you getting the public key from? Are you going to generate your keys or get it from another source?

Apple has the CommonCrypto API that can do RSA but it's not very convenient to import a public key from an outside source. (In my case it was a .net server public key).

I ended up using openssl to import the public key and rsa encrypt.
Also at the time I coded this in 2011 CommonCrypto didn't support the padding option that was being used on the server and openssl did.

A quick google turned up an example of RSA encryption using CommonCrypto.

https://launchkey.com/docs/api/encryption/objective-c/commoncrypto#encrypt

Hope this helps.

Thank you for the response :)

The key is one I will be getting from another source. Basically all I'm doing is taking an object (which is just made of a bunch of strings in the end) and encrypting it using RSA encryption and sending the string up.

I'm new to this cryptography stuff so its hard to know where to start.

Would CommonCrypto be what I use still?
 
CommonCrypto would be the Apple provided way of doing RSA if you don't want to use a third party library like openssl.

I didn't investigate too much into getting an external key into CommonCrypto as I had already determined I had to use openssl for my task so I don't know how easy that will be.

It would depend on what format the public key is in.

I'd start with getting your public key imported so it can be used to encrypt.

Here is one of Apple's docs on cryptography. I would google around for CommonCrypto and you should find some examples.

https://developer.apple.com/library...n.html#//apple_ref/doc/uid/TP40011172-CH1-SW1
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.