I am in the process of building an application for the iMac and iPhone. The goal of the application is to encrypt plain text messages, e-mails, passwords, dates, etc. I have done some research and found that 3DES would work great and is very secure. Does anyone know how to implement 3DES in Objective-C for the iPhone or Mac? Any help would be appreciated! Thanks!
3 Answers
Both iOS and OS X have the CommonCrypto
library, which provides implementations of AES, 3DES, and DES, among others. Writing your own crypto library is difficult, error prone, and likely to cause bugs. Besides which, if you write your own encryption library, then you have to declare it and go through a U.S. government approval process if you ever plan to put it in the App Store.

- 48,806
- 11
- 116
- 129
-
2Yes. Please use CommonCrypto instead of trying to write your own implementation (or copying one from somewhere else). It's easier, less error prone, and faster. – Stephen Canon Jun 25 '11 at 20:02
-
Thanks! That has saved me A LOT of trouble and it looks like it will work perfect. In that case, when you submit your app to iTunes Connect do you have to declare that you are exporting encryption software if you use **CommonCrypto** library? – Sam Spencer Jun 25 '11 at 21:28
-
RazorSharp: I don't know for sure. – BJ Homer Jun 26 '11 at 02:41
-
I cannot give legal advise, but that's pretty unlikely to bite you. Note that if you are using the Apple lib, you aren't actually exporting any crypto code. You're more prone to this problem (in the US at least) if you reimplement AES and provide it as a library. – Maarten Bodewes Jun 26 '11 at 23:53
DES is an old standard that is not secure anymore because of its short key length; 3DES is one way to get it safer (uses three times more key bits). But the new standard is AES, which you could try if you don't find (or don't like) any DES libraries out there that suits your needs. You could, for example, use OpenSSL or libgcrypt.
But I wouldn't implement any of these from scratch. Implementing cryptographic algorithms is kind of tricky. You need to be careful with padding, random number generators and you should be aware that the textbook descriptions of these algorithms are usually simplified (and not safe for real-world use). One book that might help if you really want to implement crypto is Wenbo Mao's "Modern Cryptography". If you are math-oriented you could also use Katz and Lindell's "Introduction to Modern Cryptography".

- 9,585
- 6
- 49
- 72
It probably doesn't make a lot of sense to try to re-implement DES or any other encryption algorithm in Objective-C when there are well-known versions implemented in C and/or C++. You can simply call any of those from your Objective-C program.

- 124,013
- 19
- 183
- 272
-
3For completeness... what *are* these well-known versions implemented in C/C++? – Dave DeLong Jun 25 '11 at 16:41