|
@@ -0,0 +1,123 @@
|
|
|
+package cn.kdan.pdf.tech.core.utils;
|
|
|
+
|
|
|
+import cn.kdan.pdf.tech.core.model.*;
|
|
|
+import cn.kdan.pdf.tech.core.pojo.subclass.*;
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
+import exception.BackendRuntimeException;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import utils.JsonUtils;
|
|
|
+
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author ComPDFKit-WPH 2024/1/2
|
|
|
+ * <p>
|
|
|
+ * 密钥文件解析工具类
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class KeyFileParseUtils {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取文件配置
|
|
|
+ * <p>
|
|
|
+ * 不会释放流资源
|
|
|
+ *
|
|
|
+ * @param is 文件流
|
|
|
+ * @param updateOrInit 是否更新或初始化 更新:true, 初始化:false
|
|
|
+ * @return 解析只后得信息
|
|
|
+ * @throws Exception 异常
|
|
|
+ */
|
|
|
+ public static FileContent parseKeyFile(InputStream is, boolean updateOrInit) throws Exception {
|
|
|
+ // 读取数据
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.load(is);
|
|
|
+
|
|
|
+ // 验证签名合法性
|
|
|
+ String signJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Sign"));
|
|
|
+ String serverID = properties.getProperty("ServerID");
|
|
|
+ String licenseDate = properties.getProperty("LicenseDate");
|
|
|
+ String expireDate = properties.getProperty("ExpireDate");
|
|
|
+ String users = properties.getProperty("Users");
|
|
|
+ Sign sign = JsonUtils.jsonStringToBean(signJsonStr, Sign.class);
|
|
|
+ if (!(Objects.deepEquals(sign.getServerID(),serverID)
|
|
|
+ && Objects.deepEquals(sign.getLicenseDate(),licenseDate)
|
|
|
+ && Objects.deepEquals(sign.getExpireDate(),expireDate)
|
|
|
+ && Objects.deepEquals(sign.getUsers(),users))) {
|
|
|
+ throw new BackendRuntimeException("The key file signature is invalid.");
|
|
|
+ }
|
|
|
+ FileContent fileContent = new FileContent();
|
|
|
+ // 是否是更新?
|
|
|
+ if (!updateOrInit) {
|
|
|
+ // 获取只有Init时才有的字段
|
|
|
+ String companyJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Company"));
|
|
|
+ String memberJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Member"));
|
|
|
+ String teamJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Team"));
|
|
|
+ String relationJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Relation"));
|
|
|
+ // json 转换
|
|
|
+ VppCompany vppCompany = JsonUtils.jsonStringToBean(companyJsonStr, VppCompanySubclass.class);
|
|
|
+ VppMember vppMember = JsonUtils.jsonStringToBean(memberJsonStr, VppMemberSubclass.class);
|
|
|
+ VppTeam vppTeam = JsonUtils.jsonStringToBean(teamJsonStr, VppTeamSubclass.class);
|
|
|
+ VppRTeamMemberRole vppRTeamMemberRole = JsonUtils.jsonStringToBean(relationJsonStr, VppRTeamMemberRoleSubclass.class);
|
|
|
+ fileContent.setVppCompany(vppCompany);
|
|
|
+ fileContent.setVppMember(vppMember);
|
|
|
+ fileContent.setVppTeam(vppTeam);
|
|
|
+ fileContent.setVppRTeamMemberRole(vppRTeamMemberRole);
|
|
|
+ }
|
|
|
+ // 获取通用数据
|
|
|
+ String orderJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Order"));
|
|
|
+ String subscriptionJsonStr = new RSAUtils().decryptSplit(properties.getProperty("Subscription"));
|
|
|
+ String licenseJsonStr = new RSAUtils().decryptSplit(properties.getProperty("License"));
|
|
|
+ // json 转换
|
|
|
+ Orders order = JsonUtils.jsonStringToBean(orderJsonStr, OrdersSubclass.class);
|
|
|
+ Subscriptions subscription = JsonUtils.jsonStringToBean(subscriptionJsonStr, SubscriptionsSubclass.class);
|
|
|
+ List<LicenseCodesSubclass> licenseCodesList = JsonUtils.jsonStringToList(licenseJsonStr, LicenseCodesSubclass.class);
|
|
|
+ fileContent.setOrders(order);
|
|
|
+ fileContent.setSubscriptions(subscription);
|
|
|
+ fileContent.setLicenseCodesList(licenseCodesList);
|
|
|
+ // 返回数据
|
|
|
+ return fileContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ static
|
|
|
+ class Sign {
|
|
|
+ @JsonProperty("ServerID")
|
|
|
+ private String serverID;
|
|
|
+ @JsonProperty("LicenseDate")
|
|
|
+ private String licenseDate;
|
|
|
+ @JsonProperty("ExpireDate")
|
|
|
+ private String expireDate;
|
|
|
+ @JsonProperty("Users")
|
|
|
+ private String users;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public
|
|
|
+ static
|
|
|
+ class FileContent {
|
|
|
+ private VppCompany vppCompany;
|
|
|
+ private VppMember vppMember;
|
|
|
+ private VppTeam vppTeam;
|
|
|
+ private VppRTeamMemberRole vppRTeamMemberRole;
|
|
|
+ private Orders orders;
|
|
|
+ private Subscriptions subscriptions;
|
|
|
+ private List<? extends LicenseCodes> licenseCodesList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ try (InputStream is = new FileInputStream("pengjanyon@kdanmobile.com1704179596.txt")) {
|
|
|
+ FileContent o = parseKeyFile(is, false);
|
|
|
+ System.out.println(o);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|