base64Encode 및 base64Decode 응용 프로그램

1434 단어
base64Encode   base64Decode  
/**
	 * Gets the encoding String of base64Encode by a String.
	 * 
	 * @param str
	 *            The source String.
	 * @return a new String that have been encoded.
	 */
public static String base64Encode(String str) {
	try {
		return base64Encode(str.getBytes("UTF-8"));
	} catch (Exception ex) {
		log.fatal(ex.toString());
	}
	return "";
}

/**
 * Gets the decoding String of base64Decode.
 * 
 * @param str
 *            The source String.
 * @return a new String that have been decoded.
 */
public static String base64Decode(String str) {
	return  base64Decode(str.getBytes());
	}

/**
 * Gets the encoding String of base64Encode by a byte array.
 * 
 * @param str
 *            The source byte array.
 * @return a new String that have been encoded.
 */
public static String base64Encode(byte[] str) {
	return new String((new Base64()).encode(str));
}

/**
 * Gets the decoding String of base64Decode by a byte array.
 * 
 * @param str
 *            The source byte array.
 * @return a new String that have been decoded.
 */
public static String base64Decode(byte[] str) {
	if (str != null && str.length > 0) {
		byte buf[] = (new Base64()).decode(str);
		try {
						return new String(buf, "UTF-8");
		} catch (Exception ex) {
			log.fatal(ex.toString());
		}
	}
	return "";
}

좋은 웹페이지 즐겨찾기