文章出處

介紹:

 

 

過去我常常像是否有一個幫助授權的軟件,它可以非常簡單的創建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

 
 

文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()