文章詳情頁
在 Java 中如何進(jìn)行 BASE64 編碼和解碼
瀏覽:4日期:2024-06-20 11:45:09
內(nèi)容: BASE64 編碼是一種常用的字符編碼,在很多地方都會用到。JDK 中提供了非常方便的 BASE64Encoder 和 BASE64Decoder,用它們可以非常方便的完成基于 BASE64 的編碼和解碼。下面是本人編的兩個小的函數(shù),分別用于 BASE64 的編碼和解碼: // 將 s 進(jìn)行 BASE64 編碼 public static String getBASE64(String s) { if (s == null) return null; return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ); } // 將 BASE64 編碼的字符串 s 進(jìn)行解碼 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
標(biāo)簽:
Java
相關(guān)文章:
1. 關(guān)于idea中ssm框架的編碼問題分析2. Python yield生成器和return對比代碼實例3. Python新建項目自動添加介紹和utf-8編碼的方法4. 詳解用Python調(diào)用百度地圖正/逆地理編碼API5. 用php實現(xiàn)gb2312和unicode間的編碼轉(zhuǎn)換6. php對gb編碼動態(tài)轉(zhuǎn)utf-8編碼的幾種方法評測7. ASP編碼和解碼函數(shù)詳解8. 對python中return與yield的區(qū)別詳解9. Python打印特殊符號及對應(yīng)編碼解析10. 詳解CSS玩轉(zhuǎn)圖片Base64編碼
排行榜
