I want to base64 encode a NSString. But got the wrong result. Is it the bug of iOS base64 encoding? The int number in characters[] is ASCII code of the character.
int characters[] = {119,38,149,28,73,136,86,199,8,225,36,222,129,63,27,102,41,227,39,113,90,
92,150,117,130,106,134,255,182,11,0,198,110,41,175,208,158,57,211,197};
int i = 0;
NSString *result = [[NSString alloc] init];
while ( i < 40) {
NSString *tempString = [NSString stringWithFormat:@"%c", characters[i]];
result = [result stringByAppendingString:tempString];
i++;
}
NSData *tempData = [result dataUsingEncoding:NSISOLatin1StringEncoding];
NSString *b64String = [tempData base64EncodedStringWithOptions:0];
NSLog(@"%@",b64String);
With the above code, I get the result of b64String:
dyaVHEmIVscI4STegT8bZinjJ3FaXJZ1gmqG/7YLxm4pr9CeOdPF
but the correct answer should be:
dyaVHEmIVscI4STegT8bZinjJ3FaXJZ1gmqG/7YLAMZuKa/QnjnTxQ==
Can someone help me to get the right answer ?