Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
add comment

marked as duplicate by Jason Coco, David Gelhar, Mat, sudo rm -rf, Graviton Jan 12 '12 at 9:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["        <li><a href=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.3.15.1462\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nos"], "copyright__copyright__copyright": ["r = [NSString stringWithFormat:@\"%@:%@\", [Configs userName], [Configs password]];\nNSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];\nNSString *enCodedAuthValue = [NSString stringWithFormat:@\"Basic %@\", [authData base64EncodingWithLineLength:80]];\n\nNSLog(@\"Encoded Value %@\",enCodedAuthValue);\n\nConfigs is a class where credentials have been configured\n\nshare|improve this answer\nadd comment\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}