Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux集群 > Architecture > » 正文

Base64编码解码

来源: caiwenhn2008 分享至:
package com.wilson.EDecryption; import java.io.UnsupportedEncodingException; import junit.framework.Assert; import org.apache.commons.codec.binary.Base64; import org.junit.Test; public class Base64CoderTest { public final static String ENCODING = "UTF-8"; @Test public void testBase64() throws UnsupportedEncodingException { String inputStr="Java加密"; System.out.println("原文:\t" + inputStr); String code = new String(Base64.encodeBase64(inputStr.getBytes(ENCODING)), ENCODING); System.out.println("密文:\t" + code); String outputStr = new String(Base64.decodeBase64(code.getBytes(ENCODING))); System.out.println("解密:\t" + outputStr); Assert.assertEquals(inputStr, outputStr); } }


maven dependence:
<dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.5</version> </dependency>

Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史