示例如下:
NSData* originData = [originStr dataUsingEncoding:NSASCIIStringEncoding];
NSString* encodeResult = [originData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSLog(@"encodeResult:%@",encodeResult);
NSData* decodeData = [[NSData alloc] initWithBase64EncodedString:encodeResult options:0];
NSString* decodeStr = [[NSString alloc] initWithData:decodeData encoding:NSASCIIStringEncoding];
/**
*GTM 转码
*/
-(void)GTMEncodeTest
{
NSString* originStr = @"Man";
NSString* encodeResult = nil;
NSData* originData = [originStr dataUsingEncoding:NSUTF8StringEncoding];
NSData* encodeData = [GTMBase64 encodeData:originData];
encodeResult = [[NSString alloc] initWithData:encodeData encoding:NSUTF8StringEncoding];
NSLog(@"%@",encodeResult);
}
/**
* GTM 解码
*/
-(void)GMTDecodeTest
{
NSString* encodeStr = @"TWFu";
NSString* decodeResult = nil;
NSData* encodeData = [encodeStr dataUsingEncoding:NSUTF8StringEncoding];
NSData* decodeData = [GTMBase64 decodeData:encodeData];
decodeResult = [[NSString alloc] initWithData:decodeData encoding:NSUTF8StringEncoding];
NSLog(@"%@",decodeResult);
}
iOS Base64转码(使用ios7系统自带编码库 和 GMTBase64 两种方式)
原文地址:http://blog.csdn.net/shouqiangwei/article/details/24787049