文章詳情頁
在 Java 中如何進(jìn)行 BASE64 編碼和解碼
瀏覽:3日期:2024-06-20 11:45:09
內(nèi)容: BASE64 編碼是一種常用的字符編碼,在很多地方都會(huì)用到。JDK 中提供了非常方便的 BASE64Encoder 和 BASE64Decoder,用它們可以非常方便的完成基于 BASE64 的編碼和解碼。下面是本人編的兩個(gè)小的函數(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. java使用URLDecoder和URLEncoder對(duì)中文字符進(jìn)行編碼和解碼2. PHP網(wǎng)頁UTF8編碼開發(fā)中空白的問題3. PHP 實(shí)現(xiàn)base64編碼文件上傳出現(xiàn)問題詳解4. java安全編碼指南之:表達(dá)式規(guī)則說明5. python源文件的字符編碼知識(shí)點(diǎn)詳解6. PHP 實(shí)現(xiàn) JSON 數(shù)據(jù)的編碼和解碼操作詳解7. JS Html轉(zhuǎn)義和反轉(zhuǎn)義(html編碼和解碼)的實(shí)現(xiàn)與使用方法總結(jié)8. Python 中文編碼9. 使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無亂碼的解決方法10. PHP基礎(chǔ)之流程控制8——return語句
排行榜
