leaf
leaf

Reputation: 97

Cocoa base64 decoding. And NSString initWithData:encoding: return nil

I have MIME header:

Subject: =?ISO-2022-JP?B?GyRCJzEnYidWJ1UnWSdRJ1wnURsoQg==?=
=?ISO-2022-JP?B?GyRCJ1kbKEIgGyRCLWIbKEIxNzUzNTk=?=
=?ISO-2022-JP?B?IBskQidjGyhCIBskQidjJ1EnWydkJ1EbKEI=?=
=?ISO-2022-JP?B?IBskQidXGyhCLRskQideJ2AnUidaJ10nbhsoQg==?=

When i try to decode first string GyRCJzEnYidWJ1UnWSdRJ1wnURsoQg== (base64 decode and then NSSring initWithData: encoding:), all right. My code works fine for hundreds of different MIME headers except follows...

...When i try to decode second sring GyRCJ1kbKEIgGyRCLWIbKEIxNzUzNTk=, NSString initWithData:encoding: return nil

For example, http://2cyr.com/decode/?lang=en decode all strings correctly (dont forget encode this strings from base64 befor using this site).

Upvotes: 1

Views: 566

Answers (2)

Wim Lewis
Wim Lewis

Reputation: 51

This isn't a base64 problem, it's an ISO-2022-JP problem. Actually it's a JIS-X-0208 problem. If you look at the base64-decoded (but still ISO-2022-JP encoded) string, you'll see that it contains the sequence ESC $ B - b (bytes 9 through 13). The first three are the ISO-2022-JP shift sequence to shift into JIS-X-0208-1983 (see RFC 1468 for details), and the next two are supposed to be a 2-byte encoding of a character, but if you work it out it's on line 13 of the kuten grid, which isn't defined.

tl;dr: That's not a valid character.

Upvotes: 2

Mundi
Mundi

Reputation: 80271

Maybe you are missing a final = in your string?

Upvotes: 0

Related Questions