# license **Repository Path**: lx0921/license ## Basic Information - **Project Name**: license - **Description**: 项目启动加入证书认证,通过mac地址、ip地址、cpu序列号、主板序列号多方位认证,lic证书有效则启动成功,无效则启动失败 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2025-03-13 - **Last Updated**: 2025-09-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # license #### 介绍 SpringBoot 实现 License 认证:快速校验有效期的简洁方案。 License认证通常涉及生成密钥对、签发证书以及验证有效性等步骤 应用场景 部署在客户内网环境,开发者无法控制其网络状态,需通过离线方式校验证书有效性。 授权原理 利用证书管理工具生成密钥对,私钥用于创建 License 证书,公钥验证其合法性和有效期。 #### 使用方法 1. 本地执行生成证书命令 ```bash # 1. 生成私钥库 # validity:私钥的有效期(天) # alias:私钥别称 # keystore:私钥库文件名称(生成在当前目录) # storepass:私钥库密码(获取 keystore 信息所需的密码,密钥库口令) # keypass:别名条目的密码(密钥口令) keytool -genkeypair -keysize 1024 -validity 3650 -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -keypass "private_password1234" -dname "CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH, C=CN" # 2. 把私钥库内的公钥导出到一个文件当中 # alias:私钥别称 # keystore:私钥库的名称(在当前目录查找) # storepass:私钥库的密码 # file:证书名称 keytool -exportcert -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -file "certfile.cer" # 3.再把这个证书文件导入到公钥库,certfile.cer 没用了可以删掉了 # alias:公钥名称 # file:证书名称 # keystore:公钥文件名称 # storepass:公钥库密码 keytool -import -alias "publicCert" -file "certfile.cer" -keystore "publicCerts.keystore" -storepass "public_password1234" ``` 2. 启动server服务(获取电脑信息以及生成证书) ##### 获取当前机器硬件信息 ```http request GET http://localhost:8000/license/getServerInfos ``` ##### 生成证书 ```http request POST http://localhost:8000/license/generateLicense { "subject": "license_demo", "privateAlias": "privateKey", "keyPass": "private_password1234", "storePass": "public_password1234", "licensePath": "E:\\license\\license.lic", "privateKeysStorePath": "E:\\license\\privateKeys.keystore", "issuedTime": "2025-02-12 00:00:00", "expiryTime": "2025-03-23 15:20:00", "consumerType": "user", "consumerAmount": 1, "description": "", "licenseCheckModel": { "ipAddress": [ "xxxxxxxxxxxx" ], "macAddress": [ "xxxxxxxxxxx" ], "cpuSerial": "xxxxxxxxxxxx", "mainBoardSerial": "xxxxxxxxxxxx" } } ``` 3. 配置Client服务中配置文件,随后启动,证书正常则启动成功,证书异常则启动失败