DbnBase64加密处理

package com.dbn.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils; public class DbnBase64 {
public final static String ENCODING="UTF-8";
/**
* 数据BASE64加密字符串
* @param data:需要加密的字符串
* @param additionSymbol:加密干扰符
* @return
*/
public static byte[] encode(final String data,final String additionSymbol ) {
String finalData=data;
if(!StringUtils.isBlank(additionSymbol)){
finalData=finalData+additionSymbol;
}
return Base64.encodeBase64(finalData.getBytes());
} public static String stringEncode(final String data,final String additionSymbol ) throws UnsupportedEncodingException {
if(StringUtils.isBlank(data)){
return "";
}
return new String(encode(data, additionSymbol),ENCODING);
} /**
* 数据BASE64解码字符串
* @param data:加密后的字符串
* @param additionSymbol:干扰数据
* @return
* @throws UnsupportedEncodingException
*/
public static String decode(final String data,final String additionSymbol) throws UnsupportedEncodingException {
if(StringUtils.isBlank(data)){
return "";
}
byte[] decodeString=Base64.decodeBase64(data.getBytes(ENCODING));
if(!StringUtils.isBlank(additionSymbol)){
return new String(decodeString,ENCODING).replaceAll(additionSymbol, "");
}else{
return new String(decodeString,ENCODING);
}
} /**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public static byte[] decryptBASE64(String key) throws Exception {
return new Base64().decode(key.getBytes());
} /**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public static String encryptBASE64(byte[] key) throws Exception {
return new String(new Base64().encode(key));
} public static void main(String[] args) throws UnsupportedEncodingException {
/**/ /* System.out.println(decode("bGlyZW5iaW5nQG9hdC5hd2ViLmNvbS5jbmYxNjI5OTQzLWFhNmQtNDMyZS04ZjAwLTg3N2QyNDg0NjAwZA==",""));
System.out.println(decode("aHV5YW9qaW5Ab2F0LmF3ZWIuY29tLmNuZjE2Mjk5NDMtYWE2ZC00MzJlLThmMDAtODc3ZDI0ODQ2MDBk",""));
System.out.println(decode("MQ==",""));
System.out.println(decode("MA==",""));
System.out.println(decode("ZmlsbGlucHJpY2U=",""));
System.out.println(decode("eyJkYXRhIjp7ImNvbnRlbnQiOiLmgqjlpb3vvIzor7flj5HpgIHkvaDopoHmiqXku7flnLDljLrnmoTlkI3np7DmiJbogIXljLrlj7cifSwidHlwZSI6Imh0bWwifQ==",""));
System.out.println(stringEncode("fillinprice",""));*/ // String r1=new String(decode("NDA2NDM=", ""));
// System.out.println("r1="+r1);
// String hhh=new String(DbnBase64.encode("0139951048096731"+"@im.t.dbn.cn","f0e05b83-dbc3-4bfe-bd4c-34e442a9d032"),ENCODING);
// System.out.println("hhh="+hhh);
// System.out.println(decode("bGl5dWZ1YTQxM2Q3YzUtOGJmZS00MTIzLTk1MmEtOGI4OTFiMGYwM2Fm", "c35dfc04-9c5a-4e6b-ae27-a9ad10a0db68"));
// System.out.println(decode("MTM5NjQ5NDIxMTE5NTQ4Ng==", ""));
// String r1=new String(stringEncode("admin", ""));
// System.out.println("r1="+r1);
// String hhh=new String(DbnBase64.encode("3",""),ENCODING);
// System.out.println("hhh="+hhh);
// System.out.println(decode("bGl5dWZ1YTQxM2Q3YzUtOGJmZS00MTIzLTk1MmEtOGI4OTFiMGYwM2Fm", "c35dfc04-9c5a-4e6b-ae27-a9ad10a0db68"));
// System.out.println(decode("MQ==", ""));
// System.out.println(decode("Mg==", ""));
// System.out.println(decode("k4djVS8Z+aYXIG2hKaB86F2vhb10peAy9gcPGLOMx1+qNEGw6BMASWH0NtouD1mic\\/fGPQoTSFwW\\/99Y0uarF8qk\\/kp7XyIutNUkTXqfpqbqaCeDs2nndYl9Lu9a\\/ZCxDvWwTuopfgmai9627X6GVTSMyzE6Hj6\\/0cydtbN3yAs=", ""));
// System.out.println(URLEncoder.encode(stringEncode("oa","")));
// System.out.println((String)null);
// String r1=new String(DbnBase64.encode("songguopei",""),ENCODING);
// System.out.println("r1="+r1);
// String hhh=new String(DbnBase64.encode("你好!!",""),ENCODING);
// String hhh1 = stringEncode("随时随地查猪价","");
// System.out.println(decode("5p+l54yq5Lu3",""));
// System.out.println(decode("bG9va3ByaWNlQG9hdC5hd2ViLmNvbS5jbg==",""));
// System.out.println(decode("ZmlsbGlucHJpY2VAb2F0LmF3ZWIuY29tLmNu",""));
// System.out.println(decode("aGVscEBvYXQuYXdlYi5jb20uY24=",""));
// System.out.println(decode("aGFuZ3FpbmdiYW8=",""));
// System.out.println(decode("ZmlsbGlucHJpY2U=",""));
// System.out.println(stringEncode("fillinprice", ""));
// System.out.println(URLEncoder.encode(stringEncode("25788", "")));
// System.out.println(URLEncoder.encode(stringEncode("25788", ""),"UTF-8"));
//// System.out.println(decode("bGl5dWZ1YTQxM2Q3YzUtOGJmZS00MTIzLTk1MmEtOGI4OTFiMGYwM2Fm", "c35dfc04-9c5a-4e6b-ae27-a9ad10a0db68"));
// System.out.println(decode("aHR0cDovL2ZpbGUxLmF3ZWIuY29tLmNuLy8yMDE0LzEvMTMvNzUwLmpwZw==", ""));
// System.out.println(decode("y+bKscvmtdiy6dbtvNs=", "")); //System.out.println("---"+stringEncode("liyufu", "f4f4698f-60f7-498a-bd1e-1fe0f903552d"));
//System.out.println(decode("bGl5dWZ1ZjRmNDY5OGYtNjBmNy00OThhLWJkMWUtMWZlMGY5MDM1NTJk", "f4f4698f-60f7-498a-bd1e-1fe0f903552d"));
/*String r2=DbnBase64.decode(r1,null);
System.out.println("r2="+r2);*/
String str =DbnBase64.decode("eyJyIjoiMDA0MDAyIiwidiI6IjEiLCJkIjp7ImF0dHJzIjp7Im1vYmlsZVBob25lIjoiMTg1MTUyMjIwNjciLCJzdGFydFRpbWUiOjE0NDg0MjA0MDAwMDAsImVuZFRpbWUiOjE1NDE3NDY0MTgwMDB9fX0=","");
System.out.println(new String(Base64.decodeBase64("eyJkIjp7ImF0dHJzIjp7fSwiZG9tYWlucyI6eyJhZGRDaXJjbGUiOlt7ImlkIjoiNDciLCJpbWdVcmwiOiJodHRwOi8vZmlsZXMudC5ueGluLmNvbS9wdWJsaWMveXVhbnR1LzIwMTUvMTIvMTIvMWIvMj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LM9Luosf2hotP2zPS7qCJ9XX19LCJtIjoiIiwiciI6IjAifQ==".getBytes(ENCODING)) ,"GBK")); // Syso
//System.out.println(decode("dddddd", ""));
//System.out.println(decode(URLDecoder.decode("MTEzOTk2ODU1NjQzOTY2MkBvYXQuYXdlYi5jb20uY25kNjBmZWMwNC0yYTlkLTRmZjItOGEyYi0xZTJiODNmYzRkMjI%3D"),"d60fec04-2a9d-4ff2-8a2b-1e2b83fc4d22"));
} }
上一篇:Sprint第二个冲刺(第七天)


下一篇:JS简易时钟