1

I am building an iPhone app, and I currently need to encrypt a string, store it in a file and be able to decrypt it later. As I understand, I can use symmetric encryption to do this but my key for encryption/decryption can be reversed-engineered. Assymetric encryption can solve this problem but it seems I would need a server to send the data to decrypt with the private key. Does anyone know of a way I can encrypt/decrypt the string securely in a stand-alone app?

Thanks!

gogogom3
  • 21
  • 1
  • 2
  • My question is why? An unjailbroken iPhone cannot be accessed by an outside source, and, what kind of data would be used to warrant such extreme measures? In that case, I would honestly say that you would be better off doing all data manipulation on a server, and displaying the information on the device. – Richard J. Ross III Apr 06 '12 at 23:15

4 Answers4

7

As with all matters concerning security, the question is: who are you defending against?

If you are trying to prevent the casual thief (or script kiddie) from reading an encrypted string, using the built-in iOS cryptographic services, such as the Keychain, can provide adequate-to-good security. Obviously the strength of the security will hinge in part on various factors beyond your control (notably, what sort of password lock, if any, the user has configured for the device).

The next level up would be symmetric encryption using a symmetrically encrypted key (i.e. one protected by a user passphrase). As @lukas noted, of course in principle this can be cracked, but from a practical standpoint if the user chooses a sufficiently strong passphrase for a sufficiently large key, a casual to intermediate-level attacker will be effectively thwarted.

If, on the other hand, you need to keep secrets, as Bruce Schneier would say, not from your kid sister but from major world governments, these approaches are likely to be insufficient, and you will have to explore other options, including but not limited to storing the string in multiple locations, using multiple keys, and multiple factors of authentication.

The lead Apple reference for all this (save the last option) is the Secure Coding Guide, which has references at the end of the opening page to the other more specific programming guides (covering, e.g., the Keychain and Cryptographic Services). I also heartily recommend Graham Lee's Professional Cocoa Application Security. If you want a theoretical foundation, the gold standard is Schneier's Applied Cryptography.

Conrad Shultz
  • 8,748
  • 2
  • 31
  • 33
2

This basic question is asked pretty constantly on Stackoverflow. The answer is that you cannot obfuscate yourself to security against your own customers, and you should never spend excessive money trying. I recommend the following links to find the many previous discussions:

From the above you will find several more links. But the final answer is that you are likely trying to solve the wrong problem, and the problem you think you want to solve is unsolvable.

Community
  • 1
  • 1
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
1

Does anyone know of a way I can encrypt/decrypt the string securely in a stand-alone app?

No. If someone have the physical access to the data it can be cracked. Make a webservice to solve the problem.

Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
0

Have you considered using Keychain Services?

sosborn
  • 14,676
  • 2
  • 42
  • 46