建立一個base64的類,在base64.h中天假四個函數:
+ (NSString*)encodeBase64String:(NSString*)input;
+ (NSString*)decodeBase64String:(NSString*)input;
+ (NSString*)encodeBase64Data:(NSData*)data;
+ (NSString*)decodeBase64Data:(NSData*)data;
在base64.m檔案中,實現上面4個函數:
+ (NSString*)encodeBase64String:(NSString* )input {
NSData*data = [inputdataUsingEncoding:NSUTF8StringEncodingallowLossyConversion:YES];
data = [GTMBase64encodeData:data];
NSString*base64String = [[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding] ;
returnbase64String;
}
+ (NSString*)decodeBase64String:(NSString* )input {
NSData*data = [inputdataUsingEncoding:NSUTF8StringEncodingallowLossyConversion:YES];
data = [GTMBase64decodeData:data];
NSString*base64String = [[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding] ;
returnbase64String;
}
+ (NSString*)encodeBase64Data:(NSData*)data {
data = [GTMBase64encodeData:data];
NSString*base64String = [[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding] ;
returnbase64String;
}
+ (NSString*)decodeBase64Data:(NSData*)data {
data = [GTMBase64decodeData:data];
NSString*base64String = [[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding] ;
returnbase64String;
}