1

I have this Base64 decoding code in place -

--
 (NSString *)DecodeBase64:(NSString *)Value; {
    //Return the decoded Base64 string.  string must be multiple of 4 chars in length
    NSUInteger paddedLength = Value.length + (4 - (Value.length % 4));
    NSString *paddedBase64 = [Value stringByPaddingToLength:paddedLength withString:@"=" startingAtIndex:0];
    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:paddedBase64 options:NSDataBase64DecodingIgnoreUnknownCharacters];
    NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
    return decodedString;
}
--

Decode of this string -

PD94bWwgdmVyc21vbj0iMS4wIiBlbmNvVGluZz0i

returns this string -

<?xml versmon="1.0" encoTing="

which appears incorrect, misspell of "version" and "encoding" - 2 incorrect characters.

The source string comes form a very large government body so I don't imagine that it is not correct...

Is there some problem with the code?

Rob Slater
  • 225
  • 1
  • 6
  • 1
    It is actually correct. That string decodes to that snippet. Also, there is no need for you to pad it afaik.. It'll decode properly without you having to manually pad it. – Brandon Nov 05 '17 at 08:09

1 Answers1

0

https://www.base64decode.org is giving me the same output so I think you need to check your source again :)

Terje
  • 980
  • 9
  • 15