https://web.archive.org/web/20110422225659/https://en.wikipedia.org/wiki/Base64#URL_applications
谈论base64Url - 解码
存在针对 URL 变体的修改后的 Base64,其中将不使用填充“=”,标准 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;
}
它返回一个非常小的字符集,这些字符甚至与预期结果都不相似。有任何想法吗?
原文由 ufk 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用来自 Apache Commons 的
Base64
可以配置为 URL 安全,我创建了以下函数:构造函数
Base64(true)
使解码 URL 安全。