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);
 

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐