开源 .net license tool, EasyLicense !
介绍:
过去我常常像是否有一个帮助授权的软件,它可以非常简单的创建license,并且非常容易的验证license。
这是一个非常普通和公共的功能,但是我没有找到合适的开源软件,大部分开源软件都比较复杂,并且有太多我不需要的功能。
所以我创建了这个项目,希望可以让授权的流程变的简单。
使用代码:
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 的项目,可以帮助你。
Git, 请帮忙加个star 吧。
https://github.com/EasyHelper/EasyLicense
http://git.oschina.net/EasyHelper/EasyLicense
作者:LoveJenny
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2011-07-04 浅谈Dynamic 关键字系列之二:调用属性,方法,字段
2011-07-04 浅谈Dynamic 关键字系列之一:dynamic 就是Object