我正在解码的字符串值是“ed:1234”,但它抛出了 IllegalArgumentException 错误。如果有人知道我为什么会出现此错误,我将不胜感激。
代码:
String authInfo = "ed:1234";
byte[] bytes = Base64.getDecoder().decode(authInfo);
错误:
java.lang.IllegalArgumentException: Illegal base64 character 3a
最佳答案
问题是 :
( ascii 十进制 58 或十六进制 3a)仅在一种(几种)Base64 编码方案中有效,您需要 Base64.getMimeDecoder()
。就像,
byte[] bytes = Base64.getMimeDecoder().decode(authInfo);
System.out.println(Arrays.toString(bytes));
输出(没有其他变化)
[121, -35, 118, -33]
关于java - 非法参数异常 : Illegal base64 character 3a when decoding String value using Base64. getDecode(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57264433/