0
点赞
收藏
分享

微信扫一扫

[Base64](转)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!

 

补充apache的:

import

byte[] encodeBase64 = Base64.encodeBase64(message.getBytes("UTF-8"));  
System.out.println("Result:" + new String(encodeBase64));

 

举报

相关推荐

0 条评论