Created
July 8, 2011 16:12
-
-
Save joshaber/1072169 to your computer and use it in GitHub Desktop.
base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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