Apache Commons-Codec的使用


處理常用的編碼方法的工具類包 例如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);

}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM