Apache的Base64位编码
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package com.geosun.core.utils; import org.apache.commons.codec.binary.Base64; public class Base64Utils { /** * * BASE64解码 * * @param base64 * @return */ public static byte[] decodeBASE64(String base64) { return Base64.decodeBase64(base64.getBytes()); } /** * * BASE64解码 * * @param base64 * @param changeCase * @return */ public static String decodeBASE64AsString(String base64) { byte[] bytes = decodeBASE64(base64); return new String(bytes); } /** * * BASE64编码 * * @param bytes * @return */ public static String encodeBASE64(byte[] bytes) { byte[] base64Bytes = Base64.encodeBase64(bytes); return new String(base64Bytes); } /** * * BASE64编码 * * @param str * @return */ public static String encodeBASE64(String str) { return encodeBASE64(str.getBytes()); } } |
