linux生成license,License生成秘钥

一 License 简介

开发的软件产品在交付使用的时候,往往会授权一段时间的试用期,这个时候license就派上用场了。不同于在代码中直接加上时间约束,需要重新授权的时候使用license可以避免修改源码,改动部署,授权方直接生成一个新的license发送给使用方替换掉原来的license文件即可。下面将讲述使用truelicense来实现license的生成和使用。Truelicense是一个开源的证书管理引擎,详细介绍见https://truelicense.java.net/

license于加密技术一起使用效果更好。https://www.cndba.cn/simon/article/2623

二 License使用方式

license授权机制的原理

1.生成密钥对,通过jdk 的 keytool.exe 工具生成。

2.授权者保留私钥,使用私钥对包含授权信息(如使用截止日期,MAC地址等)的license进行数字签名。

3.公钥给使用者(放在验证的代码中使用),用于验证license是否符合使用条件。

https://www.cndba.cn/simon/article/2623https://www.cndba.cn/simon/article/2623

Keytool生成秘钥

2:创建证书实例:

keytool -genkey -alias testPrivatekey -keystore testPrivatekeys.store -validity 3650

参数说明:

-genkey:生成密钥;

-alias:指定密钥对的别名,该别名是公开的;

-keystore:密钥库的路径及名称,不指定的话,默认在操作系统的用户目录下生成一个”.keystore”的文件

-validity:有效期(day)https://www.cndba.cn/simon/article/2623

如下图:

692dec1eb4b607f1ce76112d586bb56b.png

执行完上面命令后,会在bin目录下生成 testPrivatekeys.keystore 文件

https://www.cndba.cn/simon/article/2623

3:查看密钥库里面的证书

实例:

keytool -list -keystore testPrivatekeys.storehttps://www.cndba.cn/simon/article/2623

如下图:

ec0d8743c78235cf98c04909a182468b.png

4:导出到证书文件

把私匙库内的公匙导出到一个文件当中

将名为 testPrivatekeys.store的证书库中别名为 testPrivatekey 的证书条目导出到证书文件testCertfile.cer中

实例:

keytool -export -alias testPrivatekey -file testCertfile.cer -keystore testPrivatekeys.storehttps://www.cndba.cn/simon/article/2623

5:导入证书

把这个证书文件 testCertfile.cer 导入到公匙库

实例:

keytool -import -alias testPubliccert -file testCertfile.cer -keystore testPublicCerts.store

说明: 可以生成多个公钥。 如下所示:

keytool -import -alias testPubliccert2 -file testCertfile.cer -keystore testPublicCerts2.store

如下图:

47f3e0dc97fe6072eafb275cd7bef5fa.png

执行完上面命令后,会在bin目录下生成 testPublicCerts.store 文件

6:查看证书信息

keytool -printcert -file “testCertfile.cer”

https://www.cndba.cn/simon/article/2623

7:删除密钥库中的条目

keytool -delete -keystore testPrivatekeys.store -alias testPrivatekey

8:生成的私钥,公钥

最后生成文件 testPublicCerts.store , testPrivatekeys.store 拷贝出来备用。

从上面我们可以看到,密钥一共有两种:https://www.cndba.cn/simon/article/2623

<1> 密钥库,这个需要配置到服务器中。

<2> 密钥,这个需要保护好,是创建私钥的时候用的

版权声明:本文为博主原创文章,未经博主允许不得转载。

keytool license

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值