Encodeutils. Java Encryption

Source: Internet
Author: User
import java.io.UnsupportedEncodingException;import java.net.URLDecoder;import java.net.URLEncoder;import org.apache.commons.codec.DecoderException;import org.apache.commons.codec.binary.Base64;import org.apache.commons.codec.binary.Hex;import org.apache.commons.lang.StringEscapeUtils;public class EncodeUtils {private static final String DEFAULT_URL_ENCODING = "UTF-8";public static String hexEncode(byte[] input) {return Hex.encodeHexString(input);}public static byte[] hexDecode(String input) {try {return Hex.decodeHex(input.toCharArray());} catch (DecoderException e) {throw new IllegalStateException("Hex Decoder exception", e);}}public static String base64Encode(byte[] input) {return Base64.encodeBase64String(input);}public static String base64UrlSafeEncode(byte[] input) {return Base64.encodeBase64URLSafeString(input);}public static byte[] base64Decode(String input) {return Base64.decodeBase64(input);}public static String urlEncode(String input) {return urlEncode(input, "UTF-8");}public static String urlEncode(String input, String encoding) {try {return URLEncoder.encode(input, encoding);} catch (UnsupportedEncodingException e) {throw new IllegalArgumentException("Unsupported Encoding Exception", e);}}public static String urlDecode(String input) {return urlDecode(input, "UTF-8");}public static String urlDecode(String input, String encoding) {try {return URLDecoder.decode(input, encoding);} catch (UnsupportedEncodingException e) {throw new IllegalArgumentException("Unsupported Encoding Exception", e);}}public static String htmlEscape(String html) {return StringEscapeUtils.escapeHtml(html);}public static String htmlUnescape(String htmlEscaped) {return StringEscapeUtils.unescapeHtml(htmlEscaped);}public static String xmlEscape(String xml) {return StringEscapeUtils.escapeXml(xml);}public static String xtmlUnescape(String xmlEscaped) {return StringEscapeUtils.unescapeXml(xmlEscaped);}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.