【问题标题】:Illegal Argument Exception: Illegal base64 character 3a when decoding String value using Base64.getDecode()非法参数异常:使用 Base64.getDecode() 解码字符串值时出现非法 base64 字符 3a
【发布时间】:2019-07-30 04:46:44
【问题描述】:

我正在解码的字符串值为“ed:1234”,但它引发了 IllegalArgumentException 错误。如果有人知道我为什么会出现此错误,将不胜感激。

代码:

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

错误:

java.lang.IllegalArgumentException: Illegal base64 character 3a

【问题讨论】:

    标签: java spring spring-boot base64 decode


    【解决方案1】:

    问题是:ascii 十进制 58 或十六进制 3a)仅在一种(几种)Base64 编码方案中有效,您需要Base64.getMimeDecoder()。喜欢,

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

    哪个输出(没有其他变化)

    [121, -35, 118, -33]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 2021-06-03
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      相关资源
      最近更新 更多