Base64加密与解密

来源:互联网 发布:淘宝男装店铺名字 编辑:程序博客网 时间:2024/05/21 22:29
<pre name="code" class="java"><pre name="code" class="java">import java.io.IOException;import sun.misc.BASE64Decoder;import sun.misc.BASE64Encoder;public class Base64 {public static void main(String[] args) throws IOException {//加密String str="中华人民共和国";BASE64Encoder base = new BASE64Encoder();str = base.encode(str.getBytes("utf-8"));System.out.println("加密为:"+str);//解密BASE64Decoder bd = new BASE64Decoder();byte[] b = bd.decodeBuffer(str);String result = new String(b,"utf-8");System.out.println("解密为:"+result);}}

                                             
0 0