1 Star 0 Fork 212

CV大神 / LicenseDemo

forked from zifangsky / LicenseDemo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 3.16 KB
一键复制 编辑 原始数据 按行查看 历史
CV大神 提交于 2023-10-24 16:52 . 目录整理

LicenseDemo

项目介绍

在基于Spring的项目中使用 TrueLicense 生成和验证License证书(服务器许可)的示例代码

技术依赖:

  • Spring Boot:项目基础架构
  • TrueLicense :基于Java实现的生成和验证服务器许可的简单框架

环境依赖:

  • JDK8+

两个子项目说明:

  • ServerDemo:用于开发者给客户生成License证书的示例代码
  • ClientDemo模拟需要给客户部署的业务项目

ServerDemo项目:

对外发布了两个RESTful接口:

(1)获取服务器硬件信息 :

请求地址:http://127.0.0.1:7000/license/getServerInfos

获取服务器硬件信息

(2)生成证书 :

请求地址:http://127.0.0.1:7000/license/generateLicense

请求时需要在Header中添加一个 Content-Type ,其值为:application/json;charset=UTF-8。请求参数如下:

{
  "subject": "license_demo",
  "privateAlias": "privateKey",
  "keyPass": "private_password1234",
  "storePass": "public_password1234",
  "privateKeysStorePath": "E:\\privateKeys.keystore",
  "issuedTime": "2023-10-24 15:00:12",
  "expiryTime": "2024-12-31 00:00:00",
  "consumerType": "User",
  "consumerAmount": 1,
  "description": "这是证书描述信息",
  "licenseCheckModel": {
    "macAddress": [
      "00-50-56-C0-00-01",
      "50-7B-9D-F9-18-41"
    ]
  }
}

生成证书

ClientDemo项目:

项目启动时安装证书,通过cn/zifangsky/license/LicenseCheckListener.java类实现。用户登录时校验证书的可用性,通过cn/zifangsky/license/LicenseCheckInterceptor.java类实现。

通过Jdk(建议jdk1.8)自带的keytool工具生成证书:

#生成命令 keytool -genkeypair -keysize 1024 -validity 365 -alias "privateKey" -keystore "privateKeys.keystore" -storepass "water_password1234" -keypass "water_link1234" -dname "CN=bo, OU=water, O=car, L=BJ, ST=BJ, C=CN"

keysize 密钥长度 validity 私钥的有效期(单位:天) alias 私钥别称 keystore 指定私钥库文件的名称 (生成在当前目录) storepass 指定私钥库的密码 (keystore 文件存储密码) keypass 指定别名条目的密码 (私钥加解密密码) dname 证书个人信息 CN 为你的姓名 OU 为你的组织单位名称 O 为你的组织名称 L 为你所在的城市名称 ST 为你所在的省份名称 C 为你的国家名称

1、首先要用KeyTool工具来生成密钥库:(-alias别名 –validity 3650表示10年有效) keytool -genkey -alias privatekeys -keysize 1024 -keystore privateKeys.store -validity 3650

2、然后将密钥库中名称为‘privatekeys’的证书条目导出到证书文件certfile.cer中: keytool -export -alias privatekeys -file certfile.cer -keystore privateKeys.store

3、然后再把这个证书文件的信息导入到公钥库中别名为publiccert的证书条目中: keytool -import -alias publiccert -file certfile.cer -keystore publicCerts.store

最后生成的文件privateKeys.store和publicCerts.store拷贝出来备用。

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Instinctb/LicenseDemo.git
git@gitee.com:Instinctb/LicenseDemo.git
Instinctb
LicenseDemo
LicenseDemo
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891