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
?
As a result, the Transform Message component was returning this error: “Illegal base64 character 5f". This error happens when the string that you are trying to transform contains a character not recognized by the basic Base 64 Alphabet (in this case it was an underscore character).
Cg== is the base64 encode of the new line character in the latest position. So if you want to encode ABC you will get QUJD , however if you include a "return character" after ABC you will get QUJDCg== .
Q Why does an = get appended at the end? A: As a short answer: The last character ( = sign) is added only as a complement (padding) in the final process of encoding a message with a special number of characters.
The BASE64ENCODE function returns the Base64 encoded version of the binary values of a character string. The schema is SYSTOOLS. A character expression to be encoded. The maximum length in 2732 characters.
Just use this method
getMimeDecoder()
String data = "......";
byte[] dataBytes = Base64.getMimeDecoder().decode(data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With