一,工程文件。

【代码笔记】iOS-GTMBase64-LMLPHP

二,代码。

【代码笔记】iOS-GTMBase64-LMLPHP
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.title=@"GTMBase64"; [self initBase64];
}
- (void)initBase64
{
NSData *data = [@"HelloWorld" dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
//编码
NSString* encoded = [[NSString alloc] initWithData:[GTMBase64 encodeData:data] encoding:NSUTF8StringEncoding];
NSLog(@"encoded:%@", encoded);
//解码
NSString* decoded = [[NSString alloc] initWithData:[GTMBase64 decodeString:encoded] encoding:NSUTF8StringEncoding];
NSLog(@"decoded:%@", decoded);
}
【代码笔记】iOS-GTMBase64-LMLPHP

三,输出。

2015-10-13 11:09:26.324 GTMBase64Demo[2940:97657] encoded:SGVsbG9Xb3JsZA==
2015-10-13 11:09:26.324 GTMBase64Demo[2940:97657] decoded:HelloWorld
05-06 08:27