License 生成器
简介
软件许可证书(License)可在软件产品交付时,授权其使用时间和范围。当用户申请或购买变更使用时间和范围时,授权方可为用户生成新许可,替换原有许可,避免修改源码、改动部署等繁琐操作。
continew-starter-license-generator
是 ContiNew Starter 提供的基于 True License 实现的 License 生成模块,提供开箱即用的 License 生成解决方案。
配合 continew-starter-license-verifier
校验模块组成完整的 License 生成及校验解决方案。
主要特性
- 生成秘钥对,使用 Keytool 生成公私钥证书库
- 授权者保留私钥,使用私钥对包含授权信息(如使用截止日期,MAC地址等)的 License 进行数字签名
- 公钥给使用者(放在验证的代码中使用),用于验证 License 是否符合使用条件。
使用步骤
引入依赖
xml
<dependency>
<groupId>top.continew</groupId>
<artifactId>continew-starter-license-generator</artifactId>
</dependency>
API 使用
默认生成的 License 位于 FileUtil.getTmpDirPath()
下,将压缩包发送给客户端使用即可。
java
@Autowired
private LicenseCreateService licenseCreateService;
@Test
public void generate() {
// 设置证书校验参数
LicenseCreatorParamVO paramVO = new LicenseCreatorParamVO();
paramVO.setCustomerName("测试用户");
paramVO.setDescription("测试用户License");
paramVO.setKeyPass("123456abc");
paramVO.setStorePass("123456abc");
// 设置过期时间
Calendar calendar = Calendar.getInstance();
long expire = Instant.now().toEpochMilli() + (24L * 3600L * 1000L);;
calendar.setTimeInMillis(expire);
paramVO.setExpireTime(calendar.getTime());
// 设置额外校验参数(服务器信息)
LicenseExtraModel extraModel = licenseCreateService.getServerInfo();
paramVO.setLicenseExtraModel(extraModel);
licenseCreateService.generateLicense(paramVO);
}
核心依赖
依赖 | 描述 |
---|---|
top.continew:continew-starter-core | 核心模块 |
top.continew:continew-starter-license-core | License 核心模块 |
de.schlichtherle.truelicense:truelicense-core | TrueLicense (一个开源的证书管理引擎) |
net.lingala.zip4j:zip4j | Zip4j (开源的 Java 处理 zip 压缩文件的开发包) |