java.lang.IllegalArgumentException: 非法base64字符a
java.lang.IllegalArgumentException: Illegal base64 character a
我有这个字符串数据要 base64 解码
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");
byte[] v5 = Base64.getDecoder().decode(carg.getBytes());
当我 运行 此代码时出现错误:java.lang.IllegalArgumentException: Illegal base64 character a
,到目前为止,我已尝试在 carg.getBytes()
中传递 StandardCharsets.UTF_8
但没有任何结果。我在这里做错了什么?
答案只是找到一种方法来删除这些换行符,因为它们不是有效的 base64
字符。我将代码更改如下:
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());
感谢@Tom 的抬头讨论。
我有这个字符串数据要 base64 解码
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");
byte[] v5 = Base64.getDecoder().decode(carg.getBytes());
当我 运行 此代码时出现错误:java.lang.IllegalArgumentException: Illegal base64 character a
,到目前为止,我已尝试在 carg.getBytes()
中传递 StandardCharsets.UTF_8
但没有任何结果。我在这里做错了什么?
答案只是找到一种方法来删除这些换行符,因为它们不是有效的 base64
字符。我将代码更改如下:
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());
感谢@Tom 的抬头讨论。