Skip to content

Instantly share code, notes, and snippets.

@joshaber
Created July 8, 2011 16:12
Show Gist options
  • Save joshaber/1072169 to your computer and use it in GitHub Desktop.
Save joshaber/1072169 to your computer and use it in GitHub Desktop.
base64
NSString *base64Encode(NSData *data);
NSString *base64Encode(NSData *data) {
BIO *context = BIO_new(BIO_s_mem());
BIO *command = BIO_new(BIO_f_base64());
context = BIO_push(command, context);
BIO_write(context, [data bytes], (int) [data length]);
(void) BIO_flush(context);
char *outputBuffer;
long outputLength = BIO_get_mem_data(context, &outputBuffer);
NSString *encodedString = [[[NSString alloc] initWithBytes:outputBuffer length:(NSUInteger) outputLength encoding:NSUTF8StringEncoding] autorelease];
BIO_free_all(context);
return encodedString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment