Created
September 11, 2013 06:19
-
-
Save ArtSabintsev/6519920 to your computer and use it in GitHub Desktop.
A category on NSString that exploits a set of CoreFoundation methods to create Base64 encoded strings. This is a simple solution that removes the need for external Base64 libraries in projects that targets apps that support iOS 2 - iOS 6. iOS 7 has a more concrete solution, but due to NDA, I cannot post it yet.
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 *)base64EncodeString:(NSString *)stringToEncode | |
{ | |
CFHTTPMessageRef messageRef = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE); | |
CFHTTPMessageAddAuthentication(messageRef, NULL, CFSTR("AS"), (__bridge CFStringRef)stringToEncode, kCFHTTPAuthenticationSchemeBasic, FALSE); | |
CFStringRef authStringRef = CFHTTPMessageCopyHeaderFieldValue(messageRef, CFSTR("Authorization")); | |
NSString *encodedString = [(__bridge NSString *)authStringRef substringFromIndex:10]; | |
CFRelease(messageRef); | |
CFRelease(authStringRef); | |
return encodedString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment