James Montgomerie’s World Wide Web Log

iOS' Hidden Base64 Routines

It’s commonly held that iOS has no built in Base64 routines (a strange omission, if you ask me). Pootling around in the BSD headers today though, I discovered this is not entirely true. There are a couple of functions hidden away in libresolv.dylib. That’s the, err, BIND-9 DNS resolution library… If you’re not put off by linking to BIND just to get Base64 translation, it’s easy to use. Here’s the interface (publicly declared in a less readable fashion in resolv.h):

// To encode:
//
// Returns the byte length of the ASCII Base64 encoded data, or -1 on failure.
…