# springboot-licence **Repository Path**: idbb98/springboot-licence ## Basic Information - **Project Name**: springboot-licence - **Description**: 通过IP地址、MAC地址、CPU序列号、主板序列号等信息生成Licence许可证,为SpringBoot项目实现Licence许可证校验 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 3 - **Created**: 2024-04-11 - **Last Updated**: 2025-09-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: SpringBoot ## README # SpringBoot实现license认证 ## 实现思路 1. 首先需要生成密钥对,常用的方法为JDK自带的KeyTool工具生成; 2. license-server项目,使用TrueLicense和私钥生成License许可文件,注意服务端代码和私钥需要我们自己留存; 3. 使用公钥和License许可文件为客户端代码添加License校验 ### 生成密钥对 ```bash # 生成密钥 # 使用keytool工具生成一个1024位的DSA密钥对,存储类型为JKS,有效期为36500天。别名为"privateKey",存储在"privateKeys.keystore"中。 # 密钥库访问密码为"public_password1234",密钥密码为"private_password1234"。 # Distinguished Name (DN) 格式为: CN=keepc, OU=keepc, O=keepc, L=KC, ST=KC, C=CN。 keytool -genkey -keysize 1024 -keyalg DSA -storetype JKS -validity 36500 -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -keypass "private_password1234" -dname "CN=keepc, OU=keepc, O=keepc, L=KC, ST=KC, C=CN" # 导出证书 # 从"privateKeys.keystore"中导出别名为"privateKey"的证书,保存为"certfile.cer"文件。 keytool -exportcert -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -file "certfile.cer" # 导入证书 # 将"certfile.cer"证书导入到"publicCerts.keystore"中,别名为"publicCert"。 # 密钥库访问密码为"public_password1234"。 keytool -import -alias "publicCert" -file "certfile.cer" -keystore "publicCerts.keystore" -storepass "public_password1234" ``` 上述命令执行完成后会在当前目录生成三个文件: - certfile.cer 认证证书文件,暂时无用 - privateKeys.keystore 私钥文件,自己保存 - publicKeys.keystore 公钥文件,需要放到客户端项目目录里 ### licence-server生成证书 [licence-server接口文档](http://localhost:8801/doc.html) 生成证书接口参数 ```json { "subject": "license_demo", "expireTime": "2024-12-31 23:59:59", "issuedTime": "2023-01-01 00:00:00", "description": "授权给[license_demo]的证书,时长2年", "storePass": "public_password1234", "privateAlias": "privateKey", "keyPass": "private_password1234", "licensePath": "C://Users/User/Desktop/tmp/license.lic", "privateKeysStorePath": "C://Users/User/Desktop/tmp/privateKeys.keystore", "additionInfo": { //需要把这部分内容替换成获取到的服务器信息 "ipAddress": [ "192.168.2.x" ], "macAddress": [ "80-00-0B-67-5E-BC" ], "cpuSerial": "xxxBFBFF000306C3", "mainBoardSerial": "/7xxxH72/CN129xxx1G0009/" }, "consumerAmount": 1, "consumerType": "user" } ``` ### licence-client安装、校验证书 修改licence-client项目配置文件 ```json # 证书配置 license: # 证书subject subject: license_demo # 公钥别称 publicAlias: publicCert # 访问公钥的密码 storePass: public_password1234 # 证书路径 licensePath: C://Users/User/Desktop/tmp/license.lic # licensePath: /root/license-test/license.lic # 公钥存储路径 publicKeysStorePath: C://Users/User/Desktop/tmp/publicCerts.keystore # publicKeysStorePath: /root/license-test/publicCerts.keystore ``` [licence-client接口文档](http://localhost:8802/doc.html)