陈斌彬的技术博客

Stay foolish,stay hungry

使用GTMBase64编码解码字符串

使用GTMBase64需要在工程中加入三个文件

  • GTMDefines.h
  • GTMBase64.h
  • GTMBase64.m

示例代码:

#import "GTMBase64.h"

- (void)testExample
{
    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);
    [encoded release];
    [decoded release];
}