提交 921c50ee 编写于 作者: K keeplearn

'kpl23916'

上级
# 默认忽略的文件
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="javafx-learn-02" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/lib" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="renamerInitialized" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.learn</groupId>
<artifactId>javafx-learn-02</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>javafx-learn-02</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.11</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<!-- 作者 -->
<vendor>lzh</vendor>
<!-- main方法的类 -->
<mainClass>com.learn.Main</mainClass>
<!-- 运行文件名 -->
<appName>${project.build.finalName}</appName>
<!-- 图标的位置,默认位置 src/main/deploy -->
<!--<deployDir>${basedir}/src/main/resources/images/ico/Flap.ico</deployDir>-->
<!-- 菜单 -->
<needMenu>true</needMenu>
<!-- 桌面图标 -->
<needShortcut>true</needShortcut>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<!--把src/main/java目录下的properties、xm文件打包打进程序中-->
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<!--把src/main/resources目录下的properties、xm文件打包打进程序中-->
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.fxml</include>
<include>**/*.css</include>
<include>**/*.setting</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<!--把lib/目录下第三方jar包打进程序中,如systemPath目录下的jar-->
<directory>lib/</directory>
<includes>
<include>**/*.jar</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
<!-- ————————————————-->
<!-- 版权声明:本文为CSDN博主「一枚码农404」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。-->
<!-- 原文链接:https://blog.csdn.net/u012970287/article/details/127559543-->
</project>
package com.learn;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.net.URL;
import java.util.Objects;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
URL url = Objects.requireNonNull(getClass().getResource("/fxml/p1.fxml"));
Parent root = FXMLLoader.load(url);
primaryStage.setTitle("Lic生成工具");
Scene scene = new Scene(root,630,550);
scene.getStylesheets().add("/fxml/myStyle.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
\ No newline at end of file
package com.learn;
import cn.hutool.core.util.StrUtil;
import com.learn.biz.CreateLic;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
public class P1Controller {
@FXML
private Button myButton;
@FXML
private TextField systemSignTextField;
@FXML
private TextField generatedTimeTextField;
@FXML
private TextField expiredTimeTextField;
@FXML
private TextField lastValidateTimeTextField;
@FXML
private TextField versionTextField;
@FXML
private TextField pathTextField;
@FXML
private TextArea textArea2;
@FXML
private void handleButtonClick(ActionEvent event){
System.out.println("btn clicked!");
//systemSign系统标识串
String systemSign = systemSignTextField.getText();
if (StrUtil.isBlank(systemSign)){
systemSignTextField.setPromptText("系统标识串不能为空!");
return;
}
String generatedTimeStr = generatedTimeTextField.getText();
if (StrUtil.isBlank(generatedTimeStr)){
generatedTimeTextField.setPromptText("生效起始时间不能为空!");
return;
}
String expiredTimeStr = expiredTimeTextField.getText();
if (StrUtil.isBlank(expiredTimeStr)){
expiredTimeTextField.setPromptText("生效截止时间不能为空!");
return;
}
String lastValidateTimeStr = lastValidateTimeTextField.getText();
if (StrUtil.isBlank(lastValidateTimeStr)){
lastValidateTimeTextField.setPromptText("上一次校验时间初始值不能为空!");
return;
}
String version = versionTextField.getText();
if (StrUtil.isBlank(version)){
versionTextField.setPromptText("项目部署唯一版本号不能为空!");
return;
}
String path = pathTextField.getText();
if (StrUtil.isBlank(path)){
pathTextField.setPromptText("License文件生成路径不能为空!");
return;
}
String licenseSign = "";
try {
licenseSign = CreateLic.createLicense(systemSign, generatedTimeStr,
expiredTimeStr,
lastValidateTimeStr, version, path);
textArea2.setText(licenseSign);
System.out.println("license文件生成成功,文件路径:" + path);
}catch (Exception e){
textArea2.setPromptText("生成licenseSign失败!原因:"+e.getMessage());
e.printStackTrace();
}
}
}
package com.learn.biz;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.lang.Console;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
public class AESjjmUtils {
/**
* 定义1个默认的aes key
*/
private static final String DEFAULT_AES_SEAD_KEY = "20230609";
/**
* 使用默认key快速加密
* @param ywStr String 原文
* @return String
* @throws Exception
*/
public static String fastEncrypt(String ywStr) throws Exception {
return encrypt(ywStr,DEFAULT_AES_SEAD_KEY);
}
/**
* 使用默认key快速解密
* @param mwStr String 密文
* @return String
* @throws Exception
*/
public static String fastDecrypt(String mwStr) throws Exception {
return decrypt(mwStr,DEFAULT_AES_SEAD_KEY);
}
/**
* AES 加密
* @param ywStr 原文
* @param aesSeedKey 加密key
* @return String
* @throws Exception
*/
public static String encrypt(String ywStr, String aesSeedKey) throws Exception {
Console.log("AES加密的原文:{}",ywStr);
SecretKeySpec spec = getAesSecretKeySpec(aesSeedKey);
//实例化Cipher
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
//使用密钥初始化,设置为加密模式
cipher.init(Cipher.ENCRYPT_MODE, spec);
byte[] byteContent = ywStr.getBytes("utf-8");
byte[] result = cipher.doFinal(byteContent);
String aesMw = Base64.encode(result);
Console.log("AES加密结果:{}",aesMw);
return aesMw;
}
/**
* AES 解密
* @param mwStr 密文
* @param aesSeedKey 加密key
* @return String
*/
public static String decrypt(String mwStr,String aesSeedKey) throws Exception {
Console.log("AES密文:{}",mwStr);
SecretKeySpec spec = getAesSecretKeySpec(aesSeedKey);
//实例化 Cipher
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
//使用密钥初始化,设置为解密模式
cipher.init(Cipher.DECRYPT_MODE,spec);
byte[] decodeBytes = Base64.decode(mwStr);
byte[] result = cipher.doFinal(decodeBytes);
String resStr = new String(result, "utf-8");
Console.log("AES-解密结果:{}",resStr);
return resStr;
}
private static SecretKeySpec getAesSecretKeySpec(String aesSeedKey)throws Exception{
//AES 要求密钥长度为 128
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
random.setSeed(aesSeedKey.getBytes());
//利用seed值,生成1个128位的key
KeyGenerator kg = KeyGenerator.getInstance("AES");
kg.init(128, random);
//生成一个密钥
return new SecretKeySpec(kg.generateKey().getEncoded(), "AES");
}
// public static void main(String[] args) throws Exception {
// String mw = encrypt("t23t23tetw", "20230609");
// String decryptStr = decrypt(mw, "20230609");
// System.out.println(mw);
// System.out.println(decryptStr);
//
// }
}
package com.learn.biz;
import cn.hutool.core.io.FileUtil;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import java.io.File;
import java.io.FileWriter;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
public class CreateLic {
// public static void main(String[] args) throws Exception {
//
// //系统标识---由mac地址+cpu序列号 使用AES加密而来
//// String systemSign = "1jfNqzhz66e8egvhsONUXJMDNalNPTLWDO1lLBetwck=";
// //生效起始时间
//// String generatedTimeStr = "2022-05-09 00:00:00";
// //生效截止时间
//// String expiredTimeStr = "2022-05-11 00:00:00";
// //上一次校验时间(初始值)
//// String lastValidateTimeStr = "2022-05-09 00:00:01";
// //项目部署序列号(版本标识)
//// String version = "dmoiji3xkoa4p33";
// //license生成路径
//// String path = "C:\\Users\\00066\\Desktop\\license.service";
// Scanner sc = new Scanner(System.in);
//
// //输入 oiX3h/bsSgasNCegRKc7LF0+eTMY/OPFDxlx8tvoYW+witOpkegXdsTzOVWgvtXX
// System.out.println("请输入systemSign系统标识串(部署的服务获取):");
//
// String systemSign = sc.nextLine();
// System.out.println("请输入生效起始时间(格式如:2022-05-05 00:00:00):");
// String generatedTimeStr = sc.nextLine();
// System.out.println("请输入生效截止时间(格式如:2022-05-05 00:00:00):");
// String expiredTimeStr = sc.nextLine();
// System.out.println("请输入上一次校验时间初始值(格式如:2022-05-05 00:00:00):");
// String lastValidateTimeStr = sc.nextLine();
// System.out.println("请输入项目部署唯一版本号(不能带“-”):");
// String version = sc.nextLine();
// System.out.println("请输入license文件生成路径:");
// String path = sc.nextLine();
// createLicense(systemSign, generatedTimeStr, expiredTimeStr, lastValidateTimeStr, version, path);
// System.out.println("license文件生成成功,文件路径:" + path);
// }
public static String createLicense(String systemSign, String generatedTimeStr, String expiredTimeStr, String lastValidateTimeStr, String version, String path) throws Exception {
DateTimeFormatter dateTimeFormatter8 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String sign = "";
//解密系统标识得到mac地址+cpu序列号
String macAndCpu = AESjjmUtils.fastDecrypt(systemSign);
System.out.println("客户服务器mac地址和cpu序列号:" + macAndCpu);
//MAC复制-CPU序列号-生效起始时间-生效结束结束时间-软件产品序列号(项目版本唯一标识)
// String content = "A8:A1:59:41:89:36-BFEBFBFF000906EA-20220506-20220507-dmoiji3xkoa4p33";
StringBuilder signBuilder = new StringBuilder(macAndCpu);
//生效起始时间
LocalDateTime generatedDateTime = LocalDateTime.parse(generatedTimeStr, dateTimeFormatter8);
System.out.println(generatedDateTime);
long generatedTime = generatedDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
System.err.println(generatedTime);
//生效截止时间
LocalDateTime expiredDateTime = LocalDateTime.parse(expiredTimeStr, dateTimeFormatter8);
System.out.println(expiredDateTime);
long expiredTime = expiredDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
System.err.println(expiredTime);
//项目唯一标识
signBuilder.append("-").append(generatedTime).append("-").append(expiredTime).append("-").append(version);
sign = AESjjmUtils.fastEncrypt(signBuilder.toString());
System.out.println("AES加密生成签名:");
System.out.println("-----------------------------------------------------------------------------------------------");
System.out.println(sign);
System.out.println("-----------------------------------------------------------------------------------------------");
//生成licence文件
Document document = DocumentHelper.createDocument();
//根节点
Element rootEle = document.addElement("license");
//功能数据节点,扩展参数时可在此节点下扩展
Element dataEle = rootEle.addElement("features");
Element featureEle = dataEle.addElement("feature");
featureEle.addAttribute("name", "lastValidateTi");
LocalDateTime lastValidateDateTime = LocalDateTime.parse(lastValidateTimeStr, dateTimeFormatter8);
System.out.println(lastValidateDateTime);
long lastValidateTime = lastValidateDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
featureEle.addAttribute("ti", AESjjmUtils
.fastEncrypt(String.valueOf(lastValidateTime)));
//签名节点
Element signEle = rootEle.addElement("signature");
signEle.setText(sign);
System.out.println(document.asXML());
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置编码格式
format.setEncoding("UTF-8");
if (!FileUtil.exist(path)) {
new File(path).mkdirs();
}
String fullFilePath = path+File.separator+"lic.xml";
FileWriter fileWriter = new FileWriter(new File(fullFilePath));
XMLWriter xmlWriter = new XMLWriter(fileWriter, format);
// 设置是否转义,默认使用转义字符
xmlWriter.setEscapeText(false);
xmlWriter.write(document);
xmlWriter.close();
return sign;
}
}
.root {
-fx-background-color: BEIGE;
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.Region?>
<Pane stylesheets="@myStyle.css" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="551.0" prefWidth="614.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.learn.P1Controller">
<Label layoutX="257.0" layoutY="14.0" text="lic生成工具" />
<Button fx:id="myButton" layoutX="472.0" layoutY="137.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="51.0" prefWidth="88.0" text="click me!" />
<Label layoutX="66.0" layoutY="64.0" text="系统sign" />
<TextField fx:id="systemSignTextField" layoutX="226.0" layoutY="60.0" prefHeight="26.0" prefWidth="212.0" />
<Label layoutX="63.0" layoutY="109.0" text="生效起始时间" />
<TextField fx:id="generatedTimeTextField" layoutX="226.0" layoutY="105.0" prefHeight="26.0" prefWidth="212.0" text="2022-05-05 00:00:00" />
<Label layoutX="63.0" layoutY="153.0" text="生效截止时间" />
<TextField fx:id="expiredTimeTextField" layoutX="226.0" layoutY="149.0" prefHeight="26.0" prefWidth="212.0" text="2025-05-05 00:00:00" />
<Label layoutX="63.0" layoutY="200.0" text="上一次校验时间初始值" />
<TextField fx:id="lastValidateTimeTextField" layoutX="226.0" layoutY="196.0" prefHeight="26.0" prefWidth="212.0" text="2023-03-05 00:00:00" />
<Label layoutX="63.0" layoutY="240.0" text="项目部署唯一版本号" />
<TextField fx:id="versionTextField" layoutX="226.0" layoutY="236.0" prefHeight="26.0" prefWidth="212.0" text="v2xcdxc" />
<Label layoutX="66.0" layoutY="276.0" text="License文件生成路径" />
<TextField fx:id="pathTextField" layoutX="226.0" layoutY="272.0" prefHeight="26.0" prefWidth="212.0" text="F:/222" />
<TextArea fx:id="textArea2" layoutX="35.0" layoutY="315.0" prefHeight="172.0" prefWidth="546.0" />
</Pane>
package com.learn;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册