首页 技术 正文
技术 2022年11月10日
0 收藏 660 点赞 3,906 浏览 1724 个字

介绍:

过去我常常像是否有一个帮助授权的软件,它可以非常简单的创建license,并且非常容易的验证license。

这是一个非常普通和公共的功能,但是我没有找到合适的开源软件,大部分开源软件都比较复杂,并且有太多我不需要的功能。

所以我创建了这个项目,希望可以让授权的流程变的简单。

使用代码:

Easy License 非常容易使用,为了验证一个软件,你需要下面3个步骤。

1: Create a public/private Key.

if (File.Exists("privateKey.xml") || File.Exists("publicKey.xml"))
{
var result = MessageBox.Show("The key is existed, override it?", "Warning", MessageBoxButton.YesNo);
if (result == MessageBoxResult.No)
{
return;
}
}var privateKey = "";
var publicKey = "";
LicenseGenerator.GenerateLicenseKey(out privateKey, out publicKey);File.WriteAllText("privateKey.xml", privateKey);
File.WriteAllText("publicKey.xml", publicKey);MessageBox.Show("The Key is created, please backup it.");

  

2:  Use private key to create a license

if (!File.Exists("privateKey.xml"))
{
MessageBox.Show("Please create a license key first");
return;
}var privateKey = File.ReadAllText(@"privateKey.xml");
var generator = new LicenseGenerator(privateKey);var dictionary = new Dictionary<string, string>();// generate the license
var license = generator.Generate("EasyLicense", Guid.NewGuid(), DateTime.UtcNow.AddYears(1), dictionary,
LicenseType.Standard);txtLicense.Text = license;
File.WriteAllText("license.lic", license);

  

3:  Use public key to validate the license

private static void ValidateLicense()
{
if (!File.Exists("publicKey.xml"))
{
MessageBox.Show("Please create a license key first");
return;
}var publicKey = File.ReadAllText(@"publicKey.xml");var validator = new LicenseValidator(publicKey, @"license.lic");try
{
validator.AssertValidLicense();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

  

EasyLicense 内部有一个叫 LicenseTool 的工具,你可以下载源代码,运行,来看看它是怎样的创建Key,创建Licens 和验证License 的。

开源 .net license tool, EasyLicense !

并且系统还有一个Demo 的项目,可以帮助你。

开源 .net license tool, EasyLicense !

Git, 请帮忙加个star 吧。

https://github.com/EasyHelper/EasyLicense

http://git.oschina.net/EasyHelper/EasyLicense

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297