java cookie 加密_java cookie encodeBase64加密
//用encodeBase64加解密放到cookie判斷登陸
package com.ott.util;
import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;
public class CookieUtils {
/**
* 編碼
* @param cookieStr
* @return
*/
public static String encodeBase64(String cookieStr){
try {
cookieStr = new String(Base64.encodeBase64(cookieStr.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cookieStr;
}
/**
* 解碼
* @param cookieStr
* @return
*/
public static String decodeBase64(String cookieStr){
try {
cookieStr = new String(Base64.decodeBase64(cookieStr.getBytes()), "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cookieStr;
}
public static void main(String[] args) throws UnsupportedEncodingException {
String str = "ffdd訂單";
String decode = new String(Base64.encodeBase64(str.getBytes()));
System.out.println("eee" + decode);
String ddd = new String(Base64.decodeBase64(decode));
System.out.println("ddd" + ddd);
}
}
總結(jié)
以上是生活随笔為你收集整理的java cookie 加密_java cookie encodeBase64加密的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 怎么查看支付宝绑定的银行卡号
- 下一篇: 人民银行70周年纪念币