Base64的包:import org.apache.commons.codec.binary.Base64;
加密:
/** * 加密 * * @param plainText 需加密Str * @return 加密Str */ public String encodeStr(String plainText) { byte[] b = plainText.getBytes(); Base64 base64 = new Base64(); b = base64.encode(b); return new String(b); }
解密:
/** * 解密 * * @param encodeStr 加密Str * @return 解密后Str */ public String decodeStr(String encodeStr) { byte[] b = encodeStr.getBytes(); Base64 base64 = new Base64(); try { b = base64.decode(b); return new String(b); }catch (Exception e){ logger.error("",e); return ""; } }