MIHCrypto icon indicating copy to clipboard operation
MIHCrypto copied to clipboard

[NSData MIH_dataByBase64DecodingString:] not decoding valid base64 strings

Open akhilstanis opened this issue 10 years ago • 1 comments

[NSData MIH_dataByBase64DecodingString:] is behaving weird. Below code will return nil while it is a valid base64 encoded string

NSString *derString = @"MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAmZruJYeMsKl6IceG\n"
                      "TB/8gZW0m+sdVb8X617zeEHzliIK4A6q9obsizLh1hvAFkqS4ir3H4VVn7pKuxpF\n"
                      "C5oVKQIDAQABAkApWzJVPmqdwfOVFrBM3KvSg+kNtb6/MGUTRQxOS4t21ybGi2Rn\n"
                      "eXU8bucIhUjETTnwgdkRr56/e/C3Mn7BOnq1AiEAyKg/sFruB0be/VW8x4dAuM/V\n"
                      "YlOk6TGRXuE2cm4uAysCIQDD+H3ZU9r8P+3+XRxucfa9p1Lf02zuQ5yBqZaq/yHu\n"
                      "+wIgeUdP70yWT6mjP6Vhi4uRL+LWSy7ZHuUJwzoGCZXUk68CIQCzo1ZhYG/NaSDV\n"
                      "WS7VwxvmD7p1OE6TPmD5rqZRSxwk/wIhAKaDoovCCJuBlVWQlAypZ+PriMqsUHVP\n"
                      "Zg54vniNK3Yv";
NSData *der = [NSData MIH_dataByBase64DecodingString:derString];

while below code decodes it correctly

NSData *der = [[NSData alloc] initWithBase64EncodedString:derString options:NSDataBase64DecodingIgnoreUnknownCharacters];

Drilling down the code, I found out that you have used 0 for NSDataBase64DecodingOptions. And for me to get it working I had to use options:NSDataBase64DecodingIgnoreUnknownCharacters. Did you use 0 beacuse of any particular reason or is it a bug?

akhilstanis avatar Dec 31 '14 06:12 akhilstanis

I'm sorry, but I can't tell you anymore why I don't used NSDataBase64DecodingIgnoreUnknownCharacters. I'll think about changing it in the next release if I won't find the reason why I used 0.

hohl avatar Jan 11 '15 17:01 hohl