base64url在java中
http://en.wikipedia.org/wiki/Base64#URL_applications
有关base64Url会谈 - 德code
talks about base64Url - Decode
用于URL变体的修饰的Base64存在,在没有填充'='将被使用,以及标准的Base64的+和/字符被分别改为' - '和'_'
a modified Base64 for URL variant exists, where no padding '=' will be used, and the '+' and '/' characters of standard Base64 are respectively replaced by '-' and '_'
我创建了以下功能:
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;
}
它返回一个非常小的一套甚至没有像预期的结果字符。
任何想法?
it returns a very small set of characters that don't even resemble to the expected results. any ideas?
通过 Base64编码的使用
来自Apache下议院,谁可以被配置到URL的安全,我创建了以下功能:
With the usage of Base64
from Apache Commons, who can be configured to URL safe, I created the following function:
import org.apache.commons.codec.binary.Base64;
public static String base64UrlDecode(String input) {
String result = null;
Base64 decoder = new Base64(true);
byte[] decodedBytes = decoder.decode(input);
result = new String(decodedBytes);
return result;
}
构造的Base64(真)
使得解码URL安全的。
The constructor Base64(true)
makes the decoding URL-safe.