# license **Repository Path**: cuihui2012/license ## Basic Information - **Project Name**: license - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-15 - **Last Updated**: 2026-03-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 模块说明 ## 1.license-app 启动模块,包含license创建服务和验证服务 ## 2.license-core license核心模块 ## 3.license-create license创建模块 ## 4.license-verity license验证模块 # 快速开始 ## 1.创建证书库,并生成私钥和公钥 ### 1.1.首先要用KeyTool工具来生成密钥库:(-alias别名 –validity 3650表示10年有效) >keytool -genkey -alias privatekeys -keysize 1024 -keystore privateKeys.store -validity 3650 ### 1.2.然后将密钥库中名称为‘privatekeys’的证书条目导出到证书文件certfile.cer中: >keytool -export -alias privatekeys -file certfile.cer -keystore privateKeys.store ### 1.3.然后再把这个证书文件的信息导入到公钥库中别名为publiccert的证书条目中: >keytool -import -alias publiccert -file certfile.cer -keystore publicCerts.store PS:记住密钥库密码和私钥密码,最后生成的文件privateKeys.store放在license-creator模块资源目录[resources](license-creator%2Fsrc%2Fmain%2Fresources),publicCerts.store放在license-verify模块资源目录[resources](license-verify%2Fsrc%2Fmain%2Fresources) ## 2.启动证书生成服务 启动类 [LicenseCreatorApp.java](license-app%2Flicense-creator-app-test%2Fsrc%2Fmain%2Fjava%2Fcom%2Fappleyk%2Fcreator%2FLicenseCreatorApp.java) ## 3.获取服务器信息 该接口在license-core模块中,生成服务和验证服务都可调用,返回服务器信息,用于生成证书时填写服务器信息 http://127.0.0.1:8080/license/getServerInfos GET 响应示例: ```json { "status": 200, "message": "成功", "data": { "ipAddress": [ "192.168.2.11", "192.168.116.1", "10.18.205.5" ], "macAddress": [ "A0-C5-89-A6-43-43", "00-50-56-C0-00-01" ], "cpuSerial": "BFEBFBFF000806EA", "mainBoardSerial": "L1HF837007K", "registerAmount": null, "boardCheck": false, "ipCheck": false, "registerCheck": false, "macCheck": false, "cpuCheck": false }, "timeStamp": "2026-03-15 10:32:52" } ``` ## 4.证书生成 证书生成接口,接口响应会返回证书下载地址 http://127.0.0.1:8080/license/generate POST 参数说明: ```json { "subject": "证书主题,与验证服务中配置文件保持一致", "privateAlias": "私钥别名,与密钥库中设置的保持一致", "keyPass": "私钥密码", "storePass": "密钥库密码", "privateKeysStorePath": "私钥存储路径", "issuedTime": "生效时间", "expiryTime": "过期时间", "description": "证书描述", "licenseCheck": { "ipAddress": [ "服务器ip列表,若开启了ip校验,服务器ip需在其中" ], "macAddress": [ "mac地址列表,若开启了mac地址校验,mac地址需在其中" ], "cpuSerial": "cpu序列号,若开启了cpu序列号校验,cpu序列号需与其一致", "mainBoardSerial": "主板序列号,若开启了主板序列号校验,主板序列号需与其一致", "registerAmount": "注册最大人数,若开启了注册人数校验,实际注册人数应小于最大注册人数", "macCheck": "是否开启mac地址校验", "boardCheck": "是否开启主板序列号校验", "cpuCheck": "是否开启cpu序列号校验", "ipCheck": "是否开启ip地址校验", "registerCheck": "是否开启注册人数校验" } } ``` 请求示例: ```json { "subject": "bens", "privateAlias": "privateKeys", "keyPass": "since2012", "storePass": "since2012", "privateKeysStorePath": "/privateKeys.store", "issuedTime": "2025-07-04 00:00:00", "expiryTime": "2026-03-13 11:30:00", "description": "bens许可证书", "licenseCheck": { "ipAddress": [ "192.168.2.9", "2408:8221:1d:bbd0:ad77:446e:4904:a776" ], "macAddress": [ "A2-C5-89-A6-43-43", "00-50-56-C0-00-01" ], "cpuSerial": "BFEBFBFF000806EA", "mainBoardSerial": "L1HF837007K", "registerAmount": 1000, "macCheck": false, "boardCheck": false, "cpuCheck": false, "ipCheck": false, "registerCheck": false } } ``` 响应示例: ```json { "status": 200, "message": "成功", "data": { "subject": "bens", "privateAlias": "privateKeys", "keyPass": "since2012", "privateKeysStorePath": "/privateKeys.store", "storePass": "since2012", "licensePath": "D:/project/license/lic-files/20260315103821/license.lic", "issuedTime": "2025-07-04 00:00:00", "expiryTime": "2026-06-13 23:59:59", "consumerType": "user", "consumerAmount": 1, "description": "bens许可证书", "licenseCheck": { "ipAddress": [ "192.168.2.11", "192.168.116.1", "10.18.205.5" ], "macAddress": [ "A0-C5-89-A6-43-43", "00-50-56-C0-00-01" ], "cpuSerial": "BFEBFBFF000806EA", "mainBoardSerial": "L1HF837007K", "registerAmount": 1000, "boardCheck": false, "ipCheck": false, "registerCheck": false, "macCheck": false, "cpuCheck": false }, "licUrl": "http://localhost:8080/license/download?path=D:/project/license/lic-files/20260315103821/license.lic" }, "timeStamp": "2026-03-15 10:38:21" } ``` ## 5.启动证书校验服务 证书校验服务是为了方便测试license证书有效性而创建的测试服务,实际使用时对应生产环境业务服务,下文以测试服务为例演示 ### 5.1.配置license证书文件 将下载的license文件放在验证服务资源目录[resources](license-app%2Flicense-verify-app-test%2Fsrc%2Fmain%2Fresources) ### 5.2.修改pom文件 ```xml com.appleyk license-verify-spring-boot-starter 1.0-SNAPSHOT ``` ### 5.3.修改配置文件 证书主题,与生成时保持一致 ```properties springboot.license.verify.subject=bens ``` 公钥别名,与密钥库导出公钥时的设置保持一致 ```properties springboot.license.verify.publicAlias=publiccert ``` 公钥所在的位置 ```properties springboot.license.verify.publicKeysStorePath=/publicCerts.store ``` 密钥库密码 ```properties springboot.license.verify.storePass=since2012 ``` 证书存放路径(开发环境,默认放在resources下面) ```properties springboot.license.verify.licensePath=classpath:license.lic ``` 证书存放路径(生产环境,与jar放于同一目录) ```properties #springboot.license.verify.licensePath=license.lic ``` ### 5.4.启动服务 在需要校验license的接口处增加注解@VLicense,启动类 [LicenseVerifyApp.java](license-app%2Flicense-verify-app-test%2Fsrc%2Fmain%2Fjava%2Fcom%2Fappleyk%2Fverify%2FLicenseVerifyApp.java),启动日志显示证书安装成功 ### 5.5.证书验证接口 http://127.0.0.1:8081/license/hello GET 接口响应: ```text hello license ! ``` # 3.一些说明 - > license验证粒度为接口级别,如需在接口上开启License验证功能,只需要在对应的API方法上添加@VLicense注解即可 - > 内置license文件变动定时检测功能(用于证书热替换,每5s一次),如业务系统需要用到,只需要在SpringBoot启动类上,添加@EnableScheduling注解即可,核心代码 [LicenseVerifyInstallListener.java](license-verify%2Fsrc%2Fmain%2Fjava%2Fcom%2Fappleyk%2Fverify%2Flistener%2FLicenseVerifyInstallListener.java) - > license验证功能扩展,因要获取业务数据,故扩展功能应写在业务服务中去,以注册人数为例,示例代码:[CustomVerifyListenerA.java](license-app%2Flicense-verify-app-test%2Fsrc%2Fmain%2Fjava%2Fcom%2Fappleyk%2Fverify%2Flistener%2FCustomVerifyListenerA.java)