Java&JavaScript Base64 编码/解码
·
Java:
import java.nio.charset.StandardCharsets;
import java.util.Base64;
String text = "Base64 test.";
//编码
String encoded = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
System.out.println("编码结果: " + encoded);
//解码
byte[] str_arr= Base64.getDecoder().decode(encoded);
String decoded =new String(str_arr, StandardCharsets.UTF_8);
System.out.println("解码结果: " + decoded);
javascript:
var str = "Base64 test.";
var strencode = window.btoa(str);
console.info("base64 encode:" + strencode);
const strdecode = window.atob(strencode); // 解码
console.info("base64 decode:" + strdecode);
更多推荐

所有评论(0)