當前位置:
首頁 > 知識 > 開源 .net license tool, EasyLicense !

開源 .net license tool, EasyLicense !

介紹:

過去我常常像是否有一個幫助授權的軟體,它可以非常簡單的創建license,並且非常容易的驗證license。

這是一個非常普通和公共的功能,但是我沒有找到合適的開源軟體,大部分開源軟體都比較複雜,並且有太多我不需要的功能。

所以我創建了這個項目,希望可以讓授權的流程變的簡單。

使用代碼:

Easy License 非常容易使用,為了驗證一個軟體,你需要下面3個步驟。

1: Create a public/privateKey.

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 privatekey 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;

// 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 publickey 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 吧。

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 達人科技 的精彩文章:

C語言之複雜鏈表的複製
Java多線程(二)——線程安全、線程同步、線程間通信
Redis事務原理分析
2017CCPC中南地區賽 H題
Python內存管理機制

TAG:達人科技 |

您可能感興趣

AWS 發布自家版本的開源 Elasticsearch:Open Distro for Elasticsearch
開源 Resonance Audio
Facebook 開源 Detectron
Pidgin:Skype for Business 的開源替代品
可以拋棄 Python?Google 開源 Swift for TensorFlow 意味什麼
Swift For TensorFlow開源,敲響了Python的喪鐘?
Facebook開源Katran負載均衡器並公開Provisioning Tool
可以拋棄 Python 了?Google 開源 Swift for TensorFlow 意味著什麼
阻止Facebook跟蹤數據的Firefox開源插件Facebook Container
LinkedIn 開源 TonY:在 Hadoop 上運行 TensorFlow 的框架
LinkedIn 開源 TonY:在 Hadoop 上運行 TensorFlow 的框架
高可用負載均衡:開源PaaS Rainbond組件Rainbond-Entrance揭秘
Oracle開源GraphPipe:幾行代碼讓你在TensorFlow部署PyTorch模型
開源基礎設施峰會第二日:小編帶您逛Open Infrastructure Marketplace
Swift for TensorFlow 已在 GitHub 上開源,Tensor 成為 Swift 語言裡面的一等公民
Salesforce開源構建Einstein AI模型的工具
谷歌又開源了:Swift for TensorFlow
Facebook開源Mask R-CNN的PyTorch 1.0基準,比mmdetection更快、更省內存
TensorFlow、MXNet、PaddlePaddle三個開源庫對比
LinkedIn開源TonY 原生支持TensorFlow