Java Base64编码btoa
我正在使用btoa功能对前端部分的一些文本进行编码:Java Base64编码btoa,java,angular,encoding,Java,Angular,Encoding,我正在使用btoa功能对前端部分的一些文本进行编码: const encodedText = btoa(searchText); 这似乎工作得很好,解码在后端部分是这样的: byte[] decodedBytes = Base64.getDecoder().decode(searchedText); String decodedString = new String(decodedBytes, Charset.defaultCharset()); 这也很好用。然而,当使用u字母时,这似乎失败
const encodedText = btoa(searchText);
这似乎工作得很好,解码在后端部分是这样的:
byte[] decodedBytes = Base64.getDecoder().decode(searchedText);
String decodedString = new String(decodedBytes, Charset.defaultCharset());
这也很好用。然而,当使用u字母时,这似乎失败了。我的程序将其编码为A==,据我所知,它应该是w7w=
我不确定我做错了什么。你可以用
const encodedText = btoa(unescape(encodeURIComponent(searchText)));
而是先对unicode字符进行编码
有关详细信息,请参阅和
console.log(btoa('u'));
log(btoa(unescape(encodeURIComponent('u')))显然,使用encodeURIComponent(btoa(searchText))就足够了