Base64 Encoding: Illegal base64 character 3c

VMA92 :

I am trying to decode data in an xml format into bytes base64 and I am having an issues. My method is in java which takes a String data and converts it into bytes like as bellow.

String data = "......"; //string of data in xml format
byte[] dataBytes = Base64.getDecoder().decode(data);

Which failed and gave the exception like bellow.

java.lang.IllegalArgumentException: Illegal base64 character 3c
    at java.util.Base64$Decoder.decode0(Base64.java:714)
    at java.util.Base64$Decoder.decode(Base64.java:526)
    at java.util.Base64$Decoder.decode(Base64.java:549)
    at XmlReader.main(XmlReader.java:61)

Is the xml format not compatible with base64?

VMA92 :

Thanks to @luk2302 I was able to resolve the issue. Before decoding the string, I need to first encode it to Base64

    byte[] dataBytes = Base64.getEncoder().encode(data.getBytes());
    dataBytes = Base64.getDecoder().decode(dataBytes);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=443189&siteId=1