0

I have an iphone app that converts a image into NSData & then converts into base64 encoded string.

When this encoded string is submitted to server in server's database, while storing on server '+' gets converted into 'space' and so the decoder does not work properly.

I guess the issue is with default encoding of table in database. Currently its latin, i tried changing it to UTF8 but problem still exits.

Any other encoding, please help

Amol Ghotankar
  • 2,008
  • 5
  • 28
  • 42

1 Answers1

2

Of course - that has nothing to do with encoding. It is the format of the POST and GET parameters which creates a clash with base64. In http://en.wikipedia.org/wiki/Base64#Variants_summary_table you see alternatives which are designed to make base64 work with URLs etc.

One of these variants is "Base64 with URL and Filename Safe Alphabet (RFC 4648 'base64url' encoding)" which replaces the + with - and the / with _.

Another alternative would be to replace the offending characters +/= by their respective hexrepresentations with %xx - but that makes the data unnecessarily longer.

glglgl
  • 89,107
  • 13
  • 149
  • 217
  • :So what must I do? I must change encoding logic or I must convert this encoded string into url encoded string so as to be sure that universal decoder like openssl can decode my submitted data? – Amol Ghotankar Oct 10 '11 at 08:08
  • You can do any of them, depending what you have on the receiving side. Replacing is quite straightforward, and urlencoding as well - do whatever suits you best. – glglgl Oct 10 '11 at 11:33