java - 非法参数异常 : Illegal base64 character 3a when decoding String value using Base64. getDecode()

标签 java spring spring-boot base64 decode

我正在解码的字符串值是“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/

相关文章:

java - mysql批量更新限制

spring - JdbcTemplate 和 SimpleJdbcTemplate

java - 将 spring 项目中的 database.properties 包含到 web.xml 中

java - 带有 Gradle 的 Spring Boot 任务 :test? 失败

Java执行器服务连接池

java - Spring cloud AWS:发送到SQS URL,而不是队列名称

java - 数组索引越界项目欧拉问题 17

java - Spring使用注解时出错

java - Javers 审核自定义删除

spring-boot - 将 spring-cloud-starter-sleuth 依赖项添加到 Spring-Boot 应用程序中,一些 Rest Doc 测试失败