博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开源 .net license tool, EasyLicense !
阅读量:7057 次
发布时间:2019-06-28

本文共 1790 字,大约阅读时间需要 5 分钟。

使用代码:

 

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

 

1: Create a public/private Key.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 的。

 

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

 

本文转自lzwxx 51CTO博客,原文链接:http://blog.51cto.com/13064681/1944337

转载地址:http://nfmol.baihongyu.com/

你可能感兴趣的文章
Android ViewPager系列之ViewPager一屏显示多个子页面
查看>>
Spark Mllib里如何建立密集向量和稀疏向量(图文详解)
查看>>
deeplearningbook-chinese
查看>>
Android零基础入门第51节:进度条ProgressBar
查看>>
文件的行操作
查看>>
数组初始化 和 vector初始化
查看>>
java读取txt文件内容
查看>>
oracle比较一行的最大值或最小值
查看>>
Jquery中AJAX参数详细(1)-转
查看>>
Sqlserver数据库中的临时表详解
查看>>
centos更新源
查看>>
使用Postfix与Dovecot部署邮件系统
查看>>
UWP 应用获取各类系统、用户信息 (2) - 商店授权信息、零售演示模式信息、广告 ID、EAS 设备信息、硬件识别信息、移动网络信息...
查看>>
肾虚不妨少看片,人丑就该多读书
查看>>
深入理解net core中的依赖注入、Singleton、Scoped、Transient(三)
查看>>
Some Parameter Interpretation On Using Mininet
查看>>
sublime text 3创建新文件插件-AdvanceNewFile
查看>>
Inside i++
查看>>
linux bash Shell脚本经典 Fork炸弹演示及命令详解
查看>>
配置防盗链 访问控制Directory 访问控制FilesMatch
查看>>