文章詳情頁
在 Java 中如何進行 BASE64 編碼和解碼
瀏覽:3日期:2024-06-20 11:45:09
內容: BASE64 編碼是一種常用的字符編碼,在很多地方都會用到。JDK 中提供了非常方便的 BASE64Encoder 和 BASE64Decoder,用它們可以非常方便的完成基于 BASE64 的編碼和解碼。下面是本人編的兩個小的函數,分別用于 BASE64 的編碼和解碼: // 將 s 進行 BASE64 編碼 public static String getBASE64(String s) { if (s == null) return null; return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ); } // 將 BASE64 編碼的字符串 s 進行解碼 public static String getFromBASE64(String s) { if (s == null) return null; BASE64Decoder decoder = new BASE64Decoder(); try { byte[] b = decoder.decodeBuffer(s); return new String(b); } catch (Exception e) { return null; } } from:http://www.javaidea.net Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd
標簽:
Java
上一條:Java下數字類型的轉換方法下一條:淺談 Java 中 this 的使用
相關文章:
排行榜
