1

I have a base64 String and I have a function that actually encode Strings with "utf-8" like this :

public void send(Car charact,String data) {


    try {
        Log.i(TAG, "data " + URLEncoder.encode(data, "utf-8"));

        charact.setValue(URLEncoder.encode(data, "utf-8"));

   } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

So when I actually try send(myBase64String) , I have some characters that are replaced by %2F, %2B just as here http://www.degraeve.com/reference/urlencoding.php. I looked but didn't find a way to convert it into base64String. Can you advice please ? Thanks

AshBringer
  • 2,614
  • 2
  • 20
  • 42
  • Is `data` the Base64 encoded stirng? – Sotirios Delimanolis Feb 12 '15 at 20:33
  • possible duplicate of [Decode Base64 data in Java](http://stackoverflow.com/questions/469695/decode-base64-data-in-java) – ControlAltDel Feb 12 '15 at 20:35
  • Sorry, closed with the wrong question. This is right: http://stackoverflow.com/questions/13109588/base64-encoding-in-java – ControlAltDel Feb 12 '15 at 20:37
  • So I don't see the problem. You have a base64 string which you URL encode. What's the problem? – Sotirios Delimanolis Feb 12 '15 at 20:37
  • We agree that it's encoding but at the end I have characters like %F, %2B etc which I don't want. I want that when i use the send() function, it actually sends the same Base64String – AshBringer Feb 12 '15 at 20:41
  • 1
    Then don't URL encode it. Do you know what URL encoding _is_? – Sotirios Delimanolis Feb 12 '15 at 20:44
  • Can you provide an expected input and output, this might clear up the confusion... – Adam Feb 12 '15 at 20:46
  • Well for an other reason I'm forced to use urlencoding (it's sending the datas to an embedded system). Let's say I do send(characterictic,Base64String), I'm getting the Base64String like I sent it but with those characters that I told you I don't want. I have to convert it before sending it or do something but I don't know what .. And if I don't use URLEncoder , i'm sending nothing to my embedded system however I can see in my log that It's working – AshBringer Feb 12 '15 at 20:58
  • Listen, if you are creating a URL, you need to URL encode the content in that URL. The receiving side of the URL can then decode it and receive your original content, which is the base64 string. – Sotirios Delimanolis Feb 12 '15 at 22:08

0 Answers0