处理常用的编码方法的工具类包 例如DES、SHA1、MD5、Base64等.
导入包:
<!-- 这个是编码解码的 -->
<dependency>
?<groupId>commons-codec</groupId>
?<artifactId>commons-codec</artifactId>
?<version>1.10</version>
</dependency>
public class test {
???public static String encodeTest(String str){
???????Base64 base64 = new Base64();
???????try {
???????????str = base64.encodeToString(str.getBytes("UTF-8"));
???????} catch (UnsupportedEncodingException e) {
???????????e.printStackTrace();
???????}
???????System.out.println("Base64 编码后:"+str);
???????return str;
???}
???public static void decodeTest(String str){
???????Base64 base64 = new Base64();
//str = Arrays.toString(Base64.decodeBase64(str));
???????str = new String(Base64.decodeBase64(str));
???????System.out.println("Base64 解码后:"+str);
???}
}
Apache Commons-Codec的使用
原文地址:https://www.cnblogs.com/java7115/p/9675925.html