解决URL中参数中文

来源:互联网 发布:linux音乐服务器 编辑:程序博客网 时间:2024/05/08 11:02
/** * BaseCode.java * Created at 2013-12-16 * Created by hyson */package com.svw.wehr.util;import java.io.IOException;import sun.misc.BASE64Decoder;/** * <p> * ClassName: BaseCode * </p> * <p> * Description: 解决网络传输,文字解密解密 * </p> * <p> * Author: Hyson * </p> * <p> * Date: 2014-8-28 * </p> */public class BaseCode {    /**     * 加密     *      * @param s     *            字符串     * @return 加密后字符串     */    public static String getBase64(String s) {        if (s == null) {            return null;        }        return (new sun.misc.BASE64Encoder()).encode(s.getBytes());    }    /**     * 解密     *      * @param s     *            字符串     * @return 解密后字符串     */    public static String getFromBase64(String s) {        if (s == null) {            return null;        }        BASE64Decoder decoder;        decoder = new BASE64Decoder();        byte[] b = null;        try {            b = decoder.decodeBuffer(s);        } catch (IOException e) {            e.printStackTrace();        }        return new String(b);    }    }
由于URL中不允许中文出现,BASE64加密后正好为英文+数字情况,刚好解决问题

0 0
原创粉丝点击