开源 .net license tool, EasyLicense !

介绍:

 

 

过去我常常像是否有一个帮助授权的软件,它可以非常简单的创建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 的。

 

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

 

 

 

 

Git, 请帮忙加个star 吧。

 https://github.com/EasyHelper/EasyLicense

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

 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值