package com.toolkit.DES; import org.apache.commons.codec.binary.Base64; /** * base64编解码类 * * @author 刘东升 * @version 1.0 */ public class base64{ /** * 给定字节数组编码成base64的字符串 * * @param s * 字节数组 * @return 字符串 */ public static String getBASE64(byte[] s) { if (s == null) return null; byte[] tmp = null; Base64 b64 = new Base64(); try { tmp = b64.encode(s); String a = new String(tmp); return a; } catch (Exception e) { e.printStackTrace(); } finally { } return null; } /** * 给定一个字符串返回Base64解码的字节数组 * * @param s * 字符串 * @return 字节数组 */ public static byte[] getDeBASE64(String s) { if (s == null) return null; byte[] tmp = null; Base64 b64 = new Base64(); try { tmp = b64.decode(s.getBytes()); return tmp; } catch (Exception e) { e.printStackTrace(); } finally { } return null; } }