Base64编码(jdk8原生)

 

对Base64编码的支持已经被加入到Java 8官方库中,这样不需要使用第三方库就可以进行Base64编码(加密),例子代码如下:

 

        String str = "我爱笑   哈哈哈哈哈";  
        String encode = Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8));  
        System.out.println("加密后的字符串为:"+encode);  
          
        String decode=new String(Base64.getDecoder().decode(encode),StandardCharsets.UTF_8);  
        System.out.println("解密后的字符串为:"+decode); 

 

 

加密后的字符串为:5oiR54ix56yRICAg5ZOI5ZOI5ZOI5ZOI5ZOI
解密后的字符串为:我爱笑   哈哈哈哈哈

posted @ 2018-05-16 14:23  Smile_灰太狼  阅读(371)  评论(0)    收藏  举报