示例如下:
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);
}