1

I have an Android App which uses a C# web service. Now i need to send some data from the app to the web service. I want to do this with a Base64, but to let it work, i have to use Base64.URL_SAFE|Base64.NO_WRAP, or else the web service won't be called. So in my Android Code i do:

String dataToSend = "Some text"    
byte[] data = dataToSend.getBytes();
Base64.encodeToString((data), Base64.URL_SAFE|Base64.NO_WRAP);

This works okay, but the problem is that i can't decode it in C#. In the web service i do:

String data; // received data from Android
byte[] output = Convert.FromBase64String(data);

But if i run the code i get an error in C#:

System.FormatException{"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters"}

I know it's because of the URL Safe and No Wrap, but i need it to send the data. Is there a way to convert the data to a default Base64 String in C#? Or do i have replace/strip some things in the received Base64 String?

  • possible duplicate of [Code for decoding/encoding a modified base64 URL](http://stackoverflow.com/questions/1228701/code-for-decoding-encoding-a-modified-base64-url) (see the second answer) – njzk2 Oct 30 '13 at 14:24
  • You have to replace all '-','_'. string data = data.Replace('-', '+').Replace('_', '/'); – Vladimir Gondarev Oct 30 '13 at 14:29

0 Answers0