I'm trying to encode and decode base64 data. but while decoding the base64 data, it returns bunch of hex values, but i couldn't display or printout using NSlog to the original readable strings. The below code couldn't print anything, just empty.
Can anyone help ? thanks > >
NSString* msgEncoded = [[NSString alloc] initWithFormat:@"Q1NNKE1DTC9TTUEgUkNWL2FkbWluQHNldGVjcy5jb20gT1JHLyBUVkIvNDNkYzNlMzQwYWQ3Yzkp:"];
NSData* decoded = [[NSData alloc] initWithData:[self decodeBase64WithString:msgEncoded]];
NSString* plainString = [[NSString alloc]initWithData:decoded encoding:NSUTF8StringEncoding];
NSLog(@"\n Decoded string: %@ \n", plainString );
Try Google's GTMStringEncoding class. You'll need GTMDefines.h too.
To encode
NSData*
toNSString*
and back toNSData*
, use theencode:
+decode:
methods instead ofencodeString:
+decodeString:
.As a bonus you get a lot of additional useful encodings, such as the url-safe variant of Base64.
There is a built in function in NSData
If you are still having issues, try out this library: https://github.com/l4u/NSData-Base64
use it like so: