Encryption with the iPhone SDK and Security.framework

With all the great info out there about building for the iPhone, the documentation for using encryption is pretty woeful.  The developer site talks about using the Security.framework, but when it gets down to actual code, there's not much there.  And it's still a leap to go from what's provided in the simplistic examples to real world stuff. After a lot of trial and error, I did finally get both symmetric and asymmetric (public key) encryption and decryption working.  I'm going to document these in separate posts, since there's so much code to each.  Caution: No hand-holding Objective C down here.  We're using old school C, so dust off those brain cells. Here are the posts: Symmetric encryption, Asymmetric encryption Some tips that helped me wade through this:

  • I wrote the encrypt/decrypt functions as standalone code blocks, testing them from my appDidFinishLaunching stage and then exit(1)'ing.  This let me focus on the functionality without getting caught up with the iPhone code.
  • Lots of time on stackoverflow.com:  better than digging through my basement to find my old C books and notes.
  • Other time on RosettaCode
  • These examples use (uint8_t *) instead of trying to mix in (NSData *), just to stick to what definitely works in the Security.framework.

One thing that did not help me:  Apple decision to not provide the security framework for the Simulator - that probably added a few extra days of dev time by having to build and push to the iPhone, even to test a different debug statement. How hard would it have been to build that out?!  Instead we get empty functions and #ifdef warnings.  Sheesh.

Comments

[...] If I should be

[...] If I should be encrypting these files, I did find this article about using the encryption libs: Encryption with the iPhone SDK and Security.framework « Nootech Notes but this raises a few questions: 1) Not sure if these encryption methods are realistic for files [...]

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>, <shell>, <c>, <drupal6>, <java>, <javascript>, <objc>, <perl>, <php>, <python>, <rails>, <ruby>, <sql>, <xmlcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.