Another Base64 encoding option on the Mac

Update: This article is now happily obsolete. Apple have published their existing Base64 encoding methods on NSData for use back to OS X 10.6 and iOS 4.



Here's a handy technical tidbit, something that Dan discovered when trying to simplify some of the code we built back when we were getting Sandvox ready for the Mac App Store.

We needed an implementation of Base64 encoding and decoding. Foundation still doesn't have a public API after all these years (you should of course file a radar, duping Cédric Luthi's). We had been using an implementation in one of the libraries that we were trying to avoid linking to.  So Dan did some grepping through various libraries, and found that SASL has an implementation of Base64!

So we just wrapped some simple implementations around these C-based functions:

Of course, your project will need to link to libsasl2.dylib. Note that this probably isn't doable on iOS.

Alternatives

Since publicising this on Twitter, a variety of people have mentioned their own preferences. So here's a quick list:


Know any others? @message me or use my contact form

© Mike Abdullah 2007-2015