0

I have a string that is encoded as base64 by using the Convert.ToBase64String() in C#. I want to decode the same string in Java. How is it possible? I am using:

decodedString = Base64.getMimeDecoder().decode(data);

And it shows this error:

Exception in thread "Thread-6" java.lang.IllegalArgumentException: Input byte

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
  • Methods for decoding base64 in Java are well-documented. If you are having trouble getting one or more of those methods to work, and you would like help from the Stack Overflow community, make sure that your question includes a good [mcve] that reliably reproduces your problem. See also [ask], including articles linked at the bottom of that page, for more advice about how to present your question in a clear, answerable way. – Peter Duniho Jun 14 '17 at 06:15

2 Answers2

0

You can do it like below

byte [] valueDecoded = Base64.decodeBase64(data);
System.out.println("Decoded value is " + new String(valueDecoded));
Rahul Hendawe
  • 902
  • 1
  • 14
  • 39
0

You can decode it by doing the following:

// just an example (put your string here)
String encodedStr = "aGVsbG8gd29ybGQ=";

byte [] valueDecoded = java.util.Base64.getDecoder().decode(encodedStr);
System.out.println("Decoded string: " + new String(valueDecoded));

Output:

Decoded string: hello world
Michael Markidis
  • 4,163
  • 1
  • 14
  • 21