https://web.archive.org/web/20110422225659/https://en.wikipedia.org/wiki/Base64#URL_applications
该链接介绍了base64Url - 解码。
存在一种修改后的Base64变体,称为base64Url,它不使用填充符“=”,并且将标准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;
}
它返回了一个非常小的字符集,甚至不像预期结果。
sun.misc.BASE64Decoder
,因为它是内部Sun/Oracle代码(不是J2SE的一部分),并且随时可能消失。Apache Commons中的类Base64应该为您提供所需的所有功能。 - Benjamin MuschkoBASE64Decoder
是Sun的类,无论是内部还是其他。我想知道他们为什么要打破自己的命名约定。+1 - Popsreplace('_','/')
。 - Vishal John