Skip to Content
avatar image
Former Member

Issue with special characters while using Base64 encoding

Hello Experts,

I am using Base64 encoding to encode the xml message and send it to a single field. The encoding is unable to handle the special characters(ex. characters of Spanish language). The message gets encoded but the special character is converted to some junk value.

Is there any way to handle this? Below is the UDF code being used:

BASE64Encoder encoder = new BASE64Encoder();

String encoded = encoder.encode(payload.getBytes());

encoded = encoded.replace("\n","").replace("\r", "");

return encoded;

Kindly advice changes in code if required.

Thanks in advance!

Pankaj

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 23, 2017 at 12:27 PM

    Try with mentioning the encoding in the getBytes method:

    Ex: encoder.encode(payload.getBytes("UTF-8"));

    And also instead if using SUN's Base64 class use the default SAP provide a class to encode.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Manoj,

      Received below error when above code used:

      error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown
      String encoded = encoder.encode(payload.getBytes("UTF-8"));

      Thanks,

      Pankaj