1. icyspider
  2. MYCrypto


MYCrypto /

Filename Size Date modified Message
102 B
1.9 KB
18.4 KB
2.0 KB
1.8 KB
3.2 KB
193 B
552 B
11.4 KB
312 B
4.0 KB
226 B
380 B
4.2 KB
9.8 KB
3.9 KB
7.1 KB
934 B
2.2 KB
5.7 KB
3.6 KB
10.0 KB
2.3 KB
9.1 KB
6.8 KB
16.0 KB
962 B
6.6 KB
4.3 KB
9.4 KB
1.8 KB
4.8 KB
968 B
9.4 KB
5.5 KB
2.0 KB


Version 0.1 — 9 April 2009

By Jens Alfke <br>
Based in part on code by Wade Tregaskis, <br>
and sample code by Apple Computer.


MYCrypto is a high-level cryptography API for Mac OS X and iPhone. It’s an Objective-C wrapper around the system
and CSSM APIs, which are notoriously hard to use, as well as CommonCrypto, which is easier but quite limited.

MYCrypto gives you easy object-oriented interfaces to:

  • Symmmetric cryptography (session keys and password-based encryption)
  • Asymmetric cryptography (public and private keys; digital signatures)
  • Identity certificates (for use with SSL and CMS)
  • Cryptographic digests/hashes (effectively-unique IDs for data)
  • The Keychain (a secure, encrypted storage system for keys and passwords)


  • Mac OS X 10.5 or later [has been tested on 10.5.6]
  • or iPhone OS 2.0 or later [not yet tested; see Limitations section below]
  • or iPhone Simulator, for iPhone OS 2.0 or later
  • The MYUtilities library, which is used by MYCrypto.
  • Some understanding of security and cryptography on your part! Even with convenient APIs, cryptographic operations still require care and knowledge to be used safely. There are already too many examples of insecure systems that were incorrectly assembled from secure primitives; don’t add your app to that list. Please read a good overview like Practical Cryptography before attempting anything the least bit fancy.

How To Get It

hg clone /hg/hgwebdir.cgi/MYCrypto/ MYCrypto


The class hierarchy of MYCrypto looks like this:

(Italicized classes are abstract.)

Current Limitations

First off, the biggest caveat of all:

  • MYCrypto 0.1 is new code and has not yet been used in any real projects. Expect bugs. (I’m talking about my wrapper/glue code. The underlying cryptographic functionality provided by the OS is robust.)

Further issues with the 0.1 release:

  • MYCrypto does not yet work on the iPhone. It currently builds, but runs into problems at runtime. I’m currently trying to figure these out. (The iPhone OS Security APIs are very different from the Mac OS X ones, and I’m much less familiar with them.) However, it does work in the iPhone Simulator, which uses the OS X APIs.
  • Exporting symmetric keys in wrapped (encrypted) form will fail. Currently they can be exported only as raw key data.
  • Importing symmetric keys, in any form, will fail … kind of a deal-breaker for using them across two computers, unfortunately.

Current API limitations, to be remedied in the future:

  • No API for accessing passwords; fortunately there are several other utility libraries that provide this. And if your code is doing cryptographic operations, it probably needs to store the keys themselves, not passwords.
  • No bulk data encryption/decryption using public/private keys. MYKeyPair only does raw RSA crypto, which is slow and limited to small chunks of data.
  • No evaluation of trust in certificates (i.e. SecTrust and related APIs.)
  • Error reporting is too limited. Most methods indicate an error by returning nil, NULL or NO, but don’t provide the standard “out” NSError parameter to provide more information. Expect the API to be refactored in the near future to remedy this.