JDK1.8 集成了Base64加密解密包
对Base64编码的支持已经被加入到Java 8官方库中,这样不需要使用第三方库就可以进行Base64编码,例子代码如下:
String orig = "hello world!"; String desc = Base64.getEncoder().encodeToString(orig.getBytes(StandardCharsets.UTF_8)); System.out.println("加密后的字符串为:"+desc); String unDecodeStr=new String(Base64.getDecoder().decode(desc),StandardCharsets.UTF_8); System.out.println("解密后的字符串为"+unDecodeStr);
加密后的字符串为:aGVsbG8gd29ybGQh
解密后的字符串为hello world!
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。