1

Possible Duplicate:
Any base64 library on iphone-sdk?

I need to send an authorization request using REST API in Objective C with the support of Base64 encoding. It seems like objective C doesn't have any inbuilt method for that. Can anyone suggest me a good Base64 encoding library for this?

Community
  • 1
  • 1
user1120633
  • 117
  • 12
  • 1
    Just google base64 objective-c. You'll find a dozen blog entries explaining how to do it and providing reference implementations. Matt Gallagher's is quite often sourced and used. – Jason Coco Jan 10 '12 at 04:57
  • Searching SO for base64 [ios] gave pages and pages of results. Please search before you post. It's common cortousy. – Jason Coco Jan 10 '12 at 05:04
  • yes there were many. But most of them had lots of issues. I just wanted to confirm a good library that anyone of you have used before – user1120633 Jan 10 '12 at 05:35
  • 1
    I suggest using Matt Gallagher's then. His has some very minor issues but I think even those are updated since I last checked. Implementing Base64 in c is very simple and whatever you choose you only need to proof and fix a couple dozen lines of code. So just pick one, check/fix it and continue with your core dev – Jason Coco Jan 10 '12 at 05:39

1 Answers1

0

NSData+Base64.h and NSData+Base64.m resolved my issue. Below I have included the code snippet to show how you can use this classes to encode your strings.

NSString *authStr = [NSString stringWithFormat:@"%@:%@", [Configs userName], [Configs password]];
NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
NSString *enCodedAuthValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];

NSLog(@"Encoded Value %@",enCodedAuthValue);

Configs is a class where credentials have been configured

user1120633
  • 117
  • 12