Base64: java.lang.IllegalArgumentException: Illegal character
Your encoded text is [B@6499375d
. That is not Base64, something went wrong while encoding. That decoding code looks good.
Use this code to convert the byte[] to a String before adding it to the URL:
String encodedEmailString = new String(encodedEmail, "UTF-8");
// ...
String confirmLink = "Complete your registration by clicking on following"
+ "\n<a href='" + confirmationURL + encodedEmailString + "'>link</a>";
java.lang.IllegalArgumentException: Illegal base64 character a
the answer will be just to get a way to remove those line breaks as they are not valid base64
characters. I changed the code as follows:
String mfstr = "BZCaRm9ChAbA58sgSwlhzgVuPwboh2qvgcPuLxKJkLpesdHvyZtaheThUSw6%2BHItGBtgimHpXqbn%0ApggBaRR2wisjNiyQrX03eEJlet6%2BqFL6TouRr0wW3NLRZSHOHUSFtJkpq0cyXy%2FSfMVB47y93xlq%0Az845uXSTK2Vi%2FgzwFVphHd%2BTK%2FrO%2FDxJ4EfvAoW0zxeYS%2BCWnIsl%2F4ILehVYasGtxC%2FjbG1I8S%2Fc%0AZoqXIcPmPWrszbG7R1ouDQ473TyCMLx9PBsl1Z%2Bj39V4Qr01ZRw7GVP2m%2Bk4xrHg2Im1OuXpd2vl%0AKGwe5j2T1ZHtoYxCvXOOU1YeJYSR%2Ff7Kd7KbpnjvFT2Ua%2FOdHx%2FKzBoK3Yk97fdvMcelUGMxveKq%0A8C9aCXFVU1xjK81CwB72QWkK5%2B8DCjItVDFcpnVFnhk8ZwlYKU6o8jETDockNMKiDmBYqKGpnNII%0ACnQBGiWy0inWj40k8VoFNIuVK1yYzLoVvFrYR514Ex6U2AK00c0f7C2C5vISsOEp%2BW8KHG2hFW7G%0A97IgwnX3vtQc0s0SaZ%2B7SPgbxwUujlULaOa0t5W9ZDs9b7jDyBZA7m8DiFrLH2YpzpBhrHXcw%2B%2BZ%0A";
String carg = URLDecoder.decode(mfstr, "UTF-8");
carg = carg.replace("\n","");
byte[] v5 = Base64.getDecoder().decode(carg.getBytes());
Thanks @Tom for the head up discussion.
java.lang.IllegalArgumentException: Illegal base64 character 5b
So Same code was working fine in my local machine in Java8 and Java11 but in Docker Container it was failing so i used the little different method in place of getDecoder()
i used getMimeDecoder()
So previous code was
byte encodedCert[] = Base64.getDecoder().decode(CertString);
Which is now
Base64.getMimeDecoder().decode(CertString);
Illegal base64 character "a" using java.util.Base64 from within Scala
The following snippet decodes the encoding correctly:
val decodedWithMime = java.util.Base64.getMimeDecoder.decode(contentEncoded)
val convertedByteArray = decodedWithMime.map(_.toChar).mkString
as pointed out by comments, the error message Illegal Base64 character a
corresponds to the hex value for the newline character \n
. Using the Mime Decoder it is possible to decode the string without removing the newline characters beforehand.
Illegal Argument Exception: Illegal base64 character 3a when decoding String value using Base64.getDecode()
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]
Related Topics
Java Jackson Deserialization of Nested Objects
Extract Text Br Tags in Selenium Java
Passing List from Thymeleaf to Spring Controller
Error About Sun/Misc/Base64Encoder on Eclipse
Split Integer into Separate Parts
Mockito How to Mock Only the Call of a Method of the Superclass
Finding Max Value in an Array Using Recursion
How to Solve Liquibase Checksum Validation Fail After Liquibase Upgrade
Java.Lang.Noclassdeffounderror: Org/Json/Simple/Parser/Parseexception With Eclipse and Spring
Admob No Fill from Ad Server - Failed to Load Ad: 3
Check Date Between Two Other Dates Spring Data Jpa
Tomcat Is Running But 8080 Port Is Not Responding
What Is the Most Elegant Way to Check If All Values in a Boolean Array Are True
Wait Until All Threads Finish Their Work in Java
Set Current Timezone to @Jsonformat Timezone Value