Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal Argument Exception: Illegal base64 character 3a when decoding String value using Base64.getDecode()

The string value I'm decoding is "ed:1234" but it is throwing an error of IllegalArgumentException. Would greatly appreciate if someone knows why I have this error.

Code:

String authInfo = "ed:1234";
byte[] bytes = Base64.getDecoder().decode(authInfo);

Error:

java.lang.IllegalArgumentException: Illegal base64 character 3a
like image 949
Jessica Dionisio Avatar asked Sep 09 '26 00:09

Jessica Dionisio


1 Answers

The issue is the : (ascii decimal 58 or hex 3a) is only valid in one (of several) Base64 encoding schemes, you want Base64.getMimeDecoder(). Like,

byte[] bytes = Base64.getMimeDecoder().decode(authInfo);
System.out.println(Arrays.toString(bytes));

which outputs (with no other changes)

[121, -35, 118, -33]
like image 131
Elliott Frisch Avatar answered Sep 10 '26 14:09

Elliott Frisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!