溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

開(kāi)源 .net license tool, EasyLicense !

發(fā)布時(shí)間:2020-07-06 17:35:46 來(lái)源:網(wǎng)絡(luò) 閱讀:510 作者:lzwxx 欄目:編程語(yǔ)言

使用代碼:

 

Easy License 非常容易使用,為了驗(yàn)證一個(gè)軟件,你需要下面3個(gè)步驟。

 

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 內(nèi)部有一個(gè)叫 LicenseTool 的工具,你可以下載源代碼,運(yùn)行,來(lái)看看它是怎樣的創(chuàng)建Key,創(chuàng)建Licens 和驗(yàn)證License 的。

開(kāi)源 .net license tool, EasyLicense !

 

并且系統(tǒng)還有一個(gè)Demo 的項(xiàng)目,可以幫助你。

 

開(kāi)源 .net license tool, EasyLicense !


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI