改进CP56Time2a解码算法
This commit is contained in:
parent
28893ec4a5
commit
d8ab3576b7
@ -61,16 +61,11 @@ public class Aes128Cbc {
|
||||
NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchPaddingException,
|
||||
InvalidKeyException {
|
||||
|
||||
System.out.println(decryptString("6vjf229/jP0V/lvorkuYeRSKiv" +
|
||||
"+A2CMWqPaFVhjebxCxkYmRObUp9I8EoXkHLoeHYRVZwlG47PQ1N4YIn6B5bvtpP4hmFkgHvNzg7UW5+GnCSKxV9RBXxGW" +
|
||||
"/uWDiPQbgh6gflk4Ia/zvgD9ZLTyAXAm4in/dYovaWcHm08fZ" +
|
||||
"+xfGoHENu1taQO7BcWidJJtmPkVAWECKTHEbcoFcZagKjHIJV5f7V8OrmawYGQqNmA8=", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"
|
||||
System.out.println(decryptString("Fa09StzEtf3Qfmr/b91gfg==", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"
|
||||
));
|
||||
//ujNoGsWRo5MyPKYOxeofKwgPEng3xF+yhM8DDjwtwHo=
|
||||
System.out.println(encrypt("{\"StationIDs\":[\"1\"]}", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"));
|
||||
System.out.println(encrypt("{\"OperatorID\":\"MA5FNJXW9\", \"OperatorSecret\":\"Ut5UFdqDthiJyncU\"}",
|
||||
"8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"));
|
||||
System.out.println("91510105MA6DFCTD5U".substring(8, 17));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,13 +39,4 @@ public class PileTimeConfigReplyDataLogic implements ServiceLogic {
|
||||
return new ServiceResult(false);
|
||||
}
|
||||
|
||||
private static String getCP56time2a(String str) {
|
||||
|
||||
return "20" + Integer.parseInt(str.substring(12, 14), 16) + "-" + Integer.parseInt(str.substring(10, 12), 16)
|
||||
+ "-" + Integer.parseInt(str.substring(8, 10), 16) + " " + Integer.parseInt(str.substring(6, 8), 16)
|
||||
+ ":" + Integer.parseInt(str.substring(4, 6), 16) + ":"
|
||||
+ Integer.parseInt(str.substring(2, 4) + "" + str.substring(0, 2), 16) / 1000;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.xhpc.pp.utils.security;
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.xhpc.pp.utils.HexUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@ -12,24 +13,22 @@ import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
||||
|
||||
public class CP56Time2a {
|
||||
|
||||
private static String getCP56time2a(String hex) {
|
||||
|
||||
return "20" + String.format("%02d", Integer.parseInt(hex.substring(12, 14), 16)) + "-"
|
||||
+ String.format("%02d", Integer.parseInt(hex.substring(10, 12), 16)) + "-"
|
||||
+ String.format("%02d", Integer.parseInt(hex.substring(8, 10), 16)) + "T"
|
||||
+ String.format("%02d", Integer.parseInt(hex.substring(6, 8), 16)) + ":"
|
||||
+ String.format("%02d", Integer.parseInt(hex.substring(4, 6), 16)) + ":"
|
||||
+ String.format("%02d", Integer.parseInt(hex.substring(2, 4) + "" + hex.substring(0, 2), 16) / 1000);
|
||||
|
||||
}
|
||||
|
||||
public static Date cp56toDate(String hex) {
|
||||
|
||||
byte[] bytes = HexUtils.toBytes(hex);
|
||||
int milliseconds = HexUtils.reverseHexInt(hex.substring(0, 4));
|
||||
int minutes = bytes[2] & 0x3f;
|
||||
int hours = bytes[3] & 0x1f;
|
||||
int days = bytes[4] & 0x3f;
|
||||
int months = bytes[5] & 0x0f;
|
||||
int years = bytes[6] & 0x7f;
|
||||
DateTime dt = new DateTime();
|
||||
dt.setField(DateField.MILLISECOND, 0);
|
||||
dt.setField(DateField.SECOND, milliseconds / 1000);
|
||||
dt.setField(DateField.MINUTE, minutes);
|
||||
dt.setField(DateField.HOUR_OF_DAY, hours);
|
||||
dt.setField(DateField.DAY_OF_MONTH, days);
|
||||
dt.setField(DateField.MONTH, months - 1);
|
||||
dt.setField(DateField.YEAR, years + 2000);
|
||||
return dt.toCalendar().getTime();
|
||||
String dateStr = getCP56time2a(hex);
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(dateStr);
|
||||
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
public static String toCp56Hex(Date d) {
|
||||
@ -89,6 +88,13 @@ public class CP56Time2a {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
System.out.println(cp56toDate("A00F2D171F0A15"));
|
||||
System.out.println(cp56toDate("20483600010B15"));
|
||||
System.out.println(cp56toDate("50463600010B15"));
|
||||
System.out.println(toCp56Hex(cp56toDate("20483600010B15")));
|
||||
System.out.println(toCp56Hex(cp56toDate("A00F2D171F0A15")));
|
||||
System.out.println(encode(cp56toDate("A00F2D171F0A15")));
|
||||
System.out.println(encode(cp56toDate("20483600010B15")));
|
||||
// Date time = Calendar.getInstance().getTime();
|
||||
// System.out.println(String.format("--未编码--: %s", time));
|
||||
// String hex = toCp56Hex(time);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user