|
@@ -1,5 +1,6 @@
|
|
package com.huimv.manage.controller;
|
|
package com.huimv.manage.controller;
|
|
|
|
|
|
|
|
+import com.huimv.manage.util.CodeUtil;
|
|
import com.huimv.manage.util.HexUtils;
|
|
import com.huimv.manage.util.HexUtils;
|
|
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
|
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
@@ -74,30 +75,143 @@ public class ByteTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void test3() {
|
|
public void test3() {
|
|
- String str = "a5a0894c4c063803680178006002a001b003680220057505921e223441de93c6";
|
|
|
|
- //BASE64编码与解码
|
|
|
|
- String encode = DatatypeConverter.printBase64Binary(str.getBytes());
|
|
|
|
- System.out.println("1="+encode);
|
|
|
|
- byte[] decode= DatatypeConverter.parseBase64Binary(encode);
|
|
|
|
- System.out.println("2="+new String(decode));
|
|
|
|
|
|
+// String hexStr = "e5";
|
|
|
|
+// String data = hexUtils.convertHexToString(hexStr);
|
|
|
|
+// System.out.println("data="+data);
|
|
|
|
+// String[] hex2=new String[32];
|
|
|
|
+ String d1 = "";
|
|
|
|
+ for(int a=0;a<16;a++){
|
|
|
|
+// hex2[a]="e5";
|
|
|
|
+ d1+=hexUtils.convertHexToString("a5");
|
|
|
|
+ }
|
|
|
|
+// System.out.println("d1="+d1+",length="+d1.length());
|
|
|
|
+// String encode = d1;
|
|
|
|
+// String str = "a5a0894c4c063803680178006002a001b003680220057505921e223441de93c6";
|
|
|
|
+// System.out.println("0="+str+" length="+str.length());
|
|
|
|
+// //BASE64编码与解码
|
|
|
|
+// String encode = DatatypeConverter.printBase64Binary(str.getBytes());
|
|
|
|
+// System.out.println("1="+encode+" length="+encode.length());
|
|
|
|
+//
|
|
|
|
+// String encode2 = DatatypeConverter.printBase64Binary(encode.getBytes());
|
|
|
|
+// System.out.println("2="+encode2+" length="+encode2.length());
|
|
|
|
+//
|
|
|
|
+// String encode3 = DatatypeConverter.printBase64Binary(encode2.getBytes());
|
|
|
|
+// System.out.println("3="+encode3+" length="+encode3.length());
|
|
|
|
+
|
|
|
|
+// String encode = "haQcTLQHKACAACADYAKoAegBUABoBwMy20ruynTJi94=";
|
|
|
|
+// System.out.println("base64="+encode);
|
|
|
|
+//
|
|
|
|
+// //一次解码
|
|
|
|
+// byte[] decode1= DatatypeConverter.parseBase64Binary(encode);
|
|
|
|
+// String text1 = new String(decode1);
|
|
|
|
+// System.out.println("text1="+text1);
|
|
|
|
+//
|
|
|
|
+// //二次解码
|
|
|
|
+// byte[] decode2= DatatypeConverter.parseBase64Binary(text1);
|
|
|
|
+// System.out.println("text2="+new String(decode2));
|
|
|
|
|
|
//16进制编码与解码
|
|
//16进制编码与解码
|
|
- String encode1 = DatatypeConverter.printHexBinary(str.getBytes());
|
|
|
|
- System.out.println("3="+encode1);
|
|
|
|
- byte[] decode1= DatatypeConverter.parseHexBinary(encode1);
|
|
|
|
- System.out.println("4="+new String(decode1));
|
|
|
|
|
|
+// String encode1 = DatatypeConverter.printHexBinary(str.getBytes());
|
|
|
|
+// System.out.println("3="+encode1);
|
|
|
|
+// byte[] decode1= DatatypeConverter.parseHexBinary(encode1);
|
|
|
|
+// System.out.println("4="+new String(decode1));
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void test4() throws IOException {
|
|
public void test4() throws IOException {
|
|
- String data = "a5a0894c4c063803680178006002a001b003680220057505921e223441de93c6";
|
|
|
|
- BASE64Encoder encoder = new BASE64Encoder();
|
|
|
|
- String e1 = encoder.encode(data.getBytes("UTF-8"));
|
|
|
|
- System.out.println("e1="+e1);
|
|
|
|
|
|
+// String data = "a5a0894c4c063803680178006002a001b003680220057505921e223441de93c6";
|
|
|
|
+// BASE64Encoder encoder = new BASE64Encoder();
|
|
|
|
+// String e1 = encoder.encode(data.getBytes("UTF-8"));
|
|
|
|
+// System.out.println("e1="+e1);
|
|
|
|
|
|
|
|
+ String e1 = "tbrxwmAGGAFAADACIADQA+ADSADwBQCGfzde9xKKm9Q=";
|
|
BASE64Decoder decode = new BASE64Decoder();
|
|
BASE64Decoder decode = new BASE64Decoder();
|
|
byte[] d1 = decode.decodeBuffer(e1);
|
|
byte[] d1 = decode.decodeBuffer(e1);
|
|
System.out.println("d1="+new String(d1));
|
|
System.out.println("d1="+new String(d1));
|
|
|
|
+ String hexStr = hexUtils.parseByte2HexStr(d1);
|
|
|
|
+ System.out.println("二进制转成="+hexStr.toLowerCase()+" length="+hexStr.length());
|
|
|
|
+ String sourceData = "b5baf1c260061801400030022000d003e0034800f00500867f375ef7128a9bd4";
|
|
|
|
+ if(hexStr.trim().equalsIgnoreCase(sourceData)){
|
|
|
|
+ System.out.println("相等");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println("不等");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ byte[] d2 = decode.decodeBuffer(new String(d1));
|
|
|
|
+ System.out.println("d2="+new String(d2));
|
|
|
|
+ //+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
+ String hexStr1 = hexUtils.parseByte2HexStr(d2);
|
|
|
|
+ System.out.println("二次解码hexStr1="+hexStr1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void test42() throws IOException {
|
|
|
|
+// String data = "a5a0894c4c063803680178006002a001b003680220057505921e223441de93c6";
|
|
|
|
+// BASE64Encoder encoder = new BASE64Encoder();
|
|
|
|
+// String e1 = encoder.encode(data.getBytes("UTF-8"));
|
|
|
|
+// System.out.println("e1="+e1);
|
|
|
|
+
|
|
|
|
+ String e1 = "jb7L12gAeAFYAXgBcALAAZgDAAAQAiinnZH+VIu9684=";
|
|
|
|
+ BASE64Decoder decode = new BASE64Decoder();
|
|
|
|
+ byte[] d1 = decode.decodeBuffer(e1);
|
|
|
|
+ System.out.println("d1="+new String(d1));
|
|
|
|
+ String hexStr = hexUtils.parseByte2HexStr(d1);
|
|
|
|
+ System.out.println("二进制转成="+hexStr.toLowerCase()+" length="+hexStr.length());
|
|
|
|
+ String sourceData = "b5baf1c260061801400030022000d003e0034800f00500867f375ef7128a9bd4";
|
|
|
|
+ if(hexStr.trim().equalsIgnoreCase(sourceData)){
|
|
|
|
+ System.out.println("相等");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println("不等");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ byte[] d2 = decode.decodeBuffer(new String(d1));
|
|
|
|
+ System.out.println("d2="+new String(d2));
|
|
|
|
+ //+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
+ String hexStr1 = hexUtils.parseByte2HexStr(d2);
|
|
|
|
+ System.out.println("二次解码hexStr1="+hexStr1);
|
|
|
|
+ }
|
|
|
|
+ @Autowired
|
|
|
|
+ private CodeUtil codeUtil;
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void test42_1() throws IOException {
|
|
|
|
+ String encode = "tbrxwmAGGAFAADACIADQA+ADSADwBQCGfzde9xKKm9Q=";
|
|
|
|
+ System.out.println("加密密文:"+encode);
|
|
|
|
+ String hexData = codeUtil.convertBase64BinaryToHex(encode);
|
|
|
|
+ System.out.println("解密明文:"+hexData);
|
|
|
|
+
|
|
|
|
+// BASE64Decoder decode = new BASE64Decoder();
|
|
|
|
+// byte[] d1 = decode.decodeBuffer(e1);
|
|
|
|
+// System.out.println("d1="+new String(d1));
|
|
|
|
+// String hexStr = hexUtils.parseByte2HexStr(d1);
|
|
|
|
+// System.out.println("二进制转成="+hexStr.toLowerCase()+" length="+hexStr.length());
|
|
|
|
+ String sourceData = "b5baf1c260061801400030022000d003e0034800f00500867f375ef7128a9bd4";
|
|
|
|
+ System.out.println("原始数据:"+sourceData);
|
|
|
|
+ if(hexData.trim().equalsIgnoreCase(sourceData)){
|
|
|
|
+ System.out.println("相等");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println("不等");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// byte[] d2 = decode.decodeBuffer(new String(d1));
|
|
|
|
+// System.out.println("d2="+new String(d2));
|
|
|
|
+// //+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
+// String hexStr1 = hexUtils.parseByte2HexStr(d2);
|
|
|
|
+// System.out.println("二次解码hexStr1="+hexStr1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void test41() throws IOException {
|
|
|
|
+ String base64encodedString = "tbrxwmAGGAFAADACIADQA+ADSADwBQCGfzde9xKKm9Q=";
|
|
|
|
+ // 解码
|
|
|
|
+ byte[] base64decodedBytes = org.apache.commons.codec.binary.Base64.decodeBase64(base64encodedString);
|
|
|
|
+ String data1= new String(base64decodedBytes, "utf-8");
|
|
|
|
+ System.out.println("字符串1: " + data1);
|
|
|
|
+
|
|
|
|
+ // 2次解码
|
|
|
|
+ byte[] base64decodedBytes2 = org.apache.commons.codec.binary.Base64.decodeBase64(data1);
|
|
|
|
+ System.out.println("字符串2: " + new String(base64decodedBytes2, "utf-8"));
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -231,7 +345,8 @@ public class ByteTest {
|
|
byte[] bytes = d1.getBytes("UTF-8");
|
|
byte[] bytes = d1.getBytes("UTF-8");
|
|
// String asB64 = Base64.getEncoder().encodeToString(bytes);
|
|
// String asB64 = Base64.getEncoder().encodeToString(bytes);
|
|
// System.out.println("asB64="+asB64+",length="+asB64.length());
|
|
// System.out.println("asB64="+asB64+",length="+asB64.length());
|
|
-
|
|
|
|
|
|
+//xyjMKNqDwjUUxmWHzgdXirQEhophUQccNiiLZTUFudpBA
|
|
|
|
+//Dh4ceEBFAANPSyh2WssVvWvu0mKllS1gzAusgzc8gL4
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -242,4 +357,18 @@ public class ByteTest {
|
|
//
|
|
//
|
|
// System.out.println(Arrays.toString(decoded));
|
|
// System.out.println(Arrays.toString(decoded));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void test6() throws UnsupportedEncodingException {
|
|
|
|
+// String data = "haQcTLQHKACAACADYAKoAegBUABoBwMy20ruynTJi94=";
|
|
|
|
+// String base64encodedString = Base64.getEncoder().encodeToString(data.getBytes("utf-8"));
|
|
|
|
+// System.out.println("Base64 编码字符串 (基本) :" + base64encodedString);
|
|
|
|
+
|
|
|
|
+ String base64encodedString = "haQcTLQHKACAACADYAKoAegBUABoBwMy20ruynTJi94=";
|
|
|
|
+ // 解码
|
|
|
|
+ byte[] base64decodedBytes = Base64.getDecoder().decode(base64encodedString);
|
|
|
|
+ System.out.println("原始字符串: " + new String(base64decodedBytes, "utf-8"));
|
|
|
|
+ base64encodedString = Base64.getUrlEncoder().encodeToString("runoob?java8".getBytes("utf-8"));
|
|
|
|
+ System.out.println("Base64 编码字符串 (URL) :" + base64encodedString);
|
|
|
|
+ }
|
|
}
|
|
}
|