Probably take a page out of [sqlcipher](http://sqlcipher.net/) or [openSSL](http://openssl.org/).
Probably take a page out of sqlcipher or openSSL.