使用GTMBase64编码解码字符串

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

 

示例代码:

#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];
}

 

输出:

2012-04-10 12:13:10.121 fs_test[7370:b603] encoded:SGVsbG9Xb3JsZA==
2012-04-10 12:13:10.122 fs_test[7370:b603] decoded:HelloWorld
posted @ 2012-04-10 12:40  1901  阅读(4087)  评论(0编辑  收藏  举报