https://web.archive.org/web/20110422225659/https://en.wikipedia.org/wiki/Base64#URL_applications
谈谈base64Url - 解码
存在修改后的 Base64 for URL 变体,其中不使用填充“=”,标准 Base64 的“+”和“/”字符分别替换为“-”和“_”
我创建了以下函数:
public static String base64UrlDecode(String input) {
String result = null;
BASE64Decoder decoder = new BASE64Decoder();
try {
result = decoder.decodeBuffer(input.replace('-','+').replace('/','_')).toString();
}
catch (IOException e) {
System.out.println(e.getMessage());
}
return result;
}
它返回的字符集非常少,甚至与预期的结果都不相似。 有什么想法吗?
最佳答案
Java8+
import java.util.Base64;
return Base64.getUrlEncoder().encodeToString(bytes);
关于java - 在 Java 中解码 base64Url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5641303/