├── ClientImage.png
├── GeneratorImage.png
├── LicenseGenerator.csproj
├── readme.md
├── Program.cs
├── LicenseGenerator.sln
├── View
├── ClientForm.cs
├── GeneratorForm.cs
├── ClientForm.resx
├── GeneratorForm.resx
├── ClientForm.Designer.cs
└── GeneratorForm.Designer.cs
├── ViewModel
├── ViewModel.cs
├── GeneratorModel.cs
└── ClientModel.cs
├── .gitattributes
└── .gitignore
/ClientImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CosineG/LicenseGenerator/HEAD/ClientImage.png
--------------------------------------------------------------------------------
/GeneratorImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CosineG/LicenseGenerator/HEAD/GeneratorImage.png
--------------------------------------------------------------------------------
/LicenseGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net5.0-windows
6 | true
7 |
8 |
9 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | LicenseGenerator
2 | ===
3 |
4 | 一个基于RSA算法的,用于软件授权license(注册、激活码)生成和验证,并提供了生成器和客户端的GUI的简易demo。主要为了记录学习内容,仅供参考。
5 |
6 | 原理
7 | ===
8 |
9 | 基于RSA非对称加密算法,先通过私钥为授权信息签名,再将授权信息与签名组合为激活码发放到用户手中。客户端会先将激活码解码,并验证授权信息与签名是否匹配,且判断授权信息是否与用户信息相吻合,若皆能通过验证则予以软件授权。
10 |
11 | 详情见博客文章 [基于RSA算法的软件授权生成和验证 - 余弦G的博客](https://www.cosineg.com/archives/114/)
12 |
13 | 截图
14 | ===
15 |
16 | 
17 |
18 | 
19 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 | using LicenseGenerator.View;
7 |
8 | namespace LicenseGenerator
9 | {
10 | static class Program
11 | {
12 | ///
13 | /// The main entry point for the application.
14 | ///
15 | [STAThread]
16 | static void Main()
17 | {
18 | Application.SetHighDpiMode(HighDpiMode.SystemAware);
19 | Application.EnableVisualStyles();
20 | Application.SetCompatibleTextRenderingDefault(false);
21 | new ClientForm().Show();
22 | Application.Run(new GeneratorForm());
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/LicenseGenerator.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31515.178
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LicenseGenerator", "LicenseGenerator.csproj", "{1C376025-E7BC-49A3-9C8C-A8D8408E8604}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {1C376025-E7BC-49A3-9C8C-A8D8408E8604}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {1C376025-E7BC-49A3-9C8C-A8D8408E8604}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {1C376025-E7BC-49A3-9C8C-A8D8408E8604}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {1C376025-E7BC-49A3-9C8C-A8D8408E8604}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {FDA3C072-760B-442A-8F88-D2E42DC75905}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/View/ClientForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using LicenseGenerator.ViewModel;
4 |
5 | namespace LicenseGenerator.View
6 | {
7 | public partial class ClientForm : Form
8 | {
9 | private readonly ClientModel _model = new ClientModel();
10 |
11 | public ClientForm()
12 | {
13 | InitializeComponent();
14 | BindData();
15 | }
16 |
17 | ///
18 | /// 参数绑定
19 | ///
20 | private void BindData()
21 | {
22 | tbEmail.DataBindings.Add("Text", _model, nameof(_model.Email));
23 | // 得到mac地址
24 | _model.GetMACAddress();
25 | tbMAC.DataBindings.Add("Text", _model, nameof(_model.MACAddress));
26 | // 示例用公钥
27 | _model.PublicKey = @"-----BEGIN PUBLIC KEY----- MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgGFPnrvYFsHG3+NAFcVf4czqpdFX Of/eQyyFTUxwm4qjPJGLpm/agh5U3gUS6E5t9QHHSpN6hf3g8qIMgblDtTSltU4r mWEf3C8JoHK9fSsJeo2JadOSoJj8YBTPFjOTNz7/PkS0F+Sn/8to/ybzt8tUReT9 5Fxi4JWkJyxQpcWnAgMBAAE= -----END PUBLIC KEY-----";
28 | tbPublicKey.DataBindings.Add("Text", _model, nameof(_model.PublicKey));
29 | tbLicense.DataBindings.Add("Text", _model, nameof(_model.License));
30 | }
31 |
32 | private void BtnActivate_Click(object sender, EventArgs e)
33 | {
34 | _model.ActivateLicense();
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/ViewModel/ViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.ComponentModel;
5 | using System.Runtime.CompilerServices;
6 | using System.Text;
7 |
8 | namespace LicenseGenerator.ViewModel
9 | {
10 | ///
11 | /// ViewModel基类,实现了INotifyPropertyChanged接口
12 | ///
13 | public class ViewModel : INotifyPropertyChanged
14 | {
15 | public event PropertyChangedEventHandler PropertyChanged;
16 | public event PropertyChangingEventHandler PropertyChanging;
17 |
18 | ///
19 | /// 更改属性值并发出通知
20 | ///
21 | ///
22 | /// 属性对应的字段
23 | /// 更新的值
24 | ///
25 | protected bool SetProperty(ref T field, T newValue, [CallerMemberName] string propertyName = null)
26 | {
27 | if (EqualityComparer.Default.Equals(field, newValue))
28 | {
29 | return false;
30 | }
31 |
32 | OnPropertyChanging(propertyName);
33 |
34 | field = newValue;
35 |
36 | OnPropertyChanged(propertyName);
37 |
38 | return true;
39 | }
40 |
41 | protected void OnPropertyChanging(string propertyName)
42 | {
43 | PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
44 | }
45 |
46 | protected void OnPropertyChanged(string propertyName)
47 | {
48 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
49 | }
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/View/GeneratorForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using LicenseGenerator.ViewModel;
4 |
5 | namespace LicenseGenerator.View
6 | {
7 | public partial class GeneratorForm : Form
8 | {
9 | private readonly GeneratorModel _model = new GeneratorModel();
10 |
11 | public GeneratorForm()
12 | {
13 | InitializeComponent();
14 | BindData();
15 | }
16 |
17 | ///
18 | /// 参数绑定
19 | ///
20 | private void BindData()
21 | {
22 | tbEmail.DataBindings.Add("Text", _model, nameof(_model.Email));
23 | // 有效期默认一年
24 | _model.Date = DateTime.Now.AddYears(1);
25 | dtpDate.DataBindings.Add("Value", _model, nameof(_model.Date));
26 | tbMAC.DataBindings.Add("Text", _model, nameof(_model.MACAddress));
27 | // 示例用私钥
28 | _model.PrivateKey = @"-----BEGIN RSA PRIVATE KEY----- MIICWwIBAAKBgGFPnrvYFsHG3+NAFcVf4czqpdFXOf/eQyyFTUxwm4qjPJGLpm/a gh5U3gUS6E5t9QHHSpN6hf3g8qIMgblDtTSltU4rmWEf3C8JoHK9fSsJeo2JadOS oJj8YBTPFjOTNz7/PkS0F+Sn/8to/ybzt8tUReT95Fxi4JWkJyxQpcWnAgMBAAEC gYAi0/xb/tsmP6eiDi28lrSaQuFWK4H2sfYY2RzxXtxMol/rN7A6GFq5wGY2Kq46 Y+Bs4ocugYuzce9lUFSdmj4gSLJSao2MU/7W5PiML+qYWTnXH19Kl777xkXaDOVI gT8Xu65jnUC1xxzqvAqMH+lIoaI+r0RymGnBkNwWrxdoAQJBAJ9WrN6AIMBRmDaH tobaEYWK+YUK/UZThousyBQ02DFGgq/L6FyGD4HPkQzletab6Hux4JpNDgjUD4gw xnN7qgcCQQCcWAw0pswOZMBX/gFFwWTpXnYOQQrIh4ht434ebHlYxub50FEJ/TGd bYBJW5dk0hnohmSXPuzyAyjrF9fyUJ9hAkAFq3PjRvPjZAPijNm12rSc5+ERFt8E TZyQA8nqziaTOksULlFKWYrbt6MVrmS8ljejjyTK2MsTDViwI+wr186pAkAdNOma 0GogajvwdDgiot1KJ2ZghVARZBhdhvkhj9wfdJDjrEHnXtBs+27SxXSD1igW4zxZ cNzs3SBAwuSJlPwhAkEAnqGIRk7093CALK3jUKtBH/xkXPeZhVTABNbIHuiec00M EDOCN0Fnba5EDT18hqHKfGpTK1hvnk8gA5vatZFyfA== -----END RSA PRIVATE KEY-----";
29 | tbPrivateKey.DataBindings.Add("Text", _model, nameof(_model.PrivateKey));
30 | tbLicense.DataBindings.Add("Text", _model, nameof(_model.License));
31 | }
32 |
33 | private void BtnGenerate_Click(object sender, EventArgs e)
34 | {
35 | _model.GenerateLicense();
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/ViewModel/GeneratorModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Security.Cryptography;
3 | using System.Text.Json;
4 | using System.Text.Json.Serialization;
5 | using System.Windows.Forms;
6 |
7 | namespace LicenseGenerator.ViewModel
8 | {
9 | public class GeneratorModel : ViewModel
10 | {
11 | private string _email;
12 | private DateTime _date;
13 | private string _macAddress;
14 | private string _privateKey;
15 | private string _license;
16 |
17 | public string Email
18 | {
19 | get => _email;
20 | set => SetProperty(ref _email, value);
21 | }
22 |
23 | public DateTime Date
24 | {
25 | get => _date;
26 | set => SetProperty(ref _date, value);
27 | }
28 |
29 | public string MACAddress
30 | {
31 | get => _macAddress;
32 | set => SetProperty(ref _macAddress, value);
33 | }
34 |
35 | [JsonIgnore]
36 | public string PrivateKey
37 | {
38 | get => _privateKey;
39 | set => SetProperty(ref _privateKey, value);
40 | }
41 |
42 | [JsonIgnore]
43 | public string License
44 | {
45 | get => _license;
46 | set => SetProperty(ref _license, value);
47 | }
48 |
49 | public void GenerateLicense()
50 | {
51 | // 授权信息,为Json格式
52 | var data = JsonSerializer.SerializeToUtf8Bytes(this);
53 | // 导入私钥
54 | var rsa = new RSACryptoServiceProvider();
55 | try
56 | {
57 | rsa.ImportFromPem(PrivateKey.AsSpan());
58 | }
59 | catch (ArgumentException)
60 | {
61 | MessageBox.Show("私钥错误!");
62 | return;
63 | }
64 |
65 | // 密钥由授权信息长度+授权信息+授权信息签名组成,以Base64的形式呈现
66 | // 用2个byte来存储信息长度
67 | var dataLen = data.Length;
68 | var dataLenByte = new byte[] {(byte) (dataLen >> 8), (byte) dataLen};
69 | var dataSigned = rsa.SignData(data, new SHA1CryptoServiceProvider());
70 | var dataCombined = new byte[dataLenByte.Length + data.Length + dataSigned.Length];
71 | dataLenByte.CopyTo(dataCombined, 0);
72 | data.CopyTo(dataCombined, dataLenByte.Length);
73 | dataSigned.CopyTo(dataCombined, dataLenByte.Length + data.Length);
74 | License = Convert.ToBase64String(dataCombined);
75 | }
76 | }
77 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/View/ClientForm.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/View/GeneratorForm.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/ViewModel/ClientModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Net.NetworkInformation;
4 | using System.Security.Cryptography;
5 | using System.Text.Json;
6 | using System.Windows.Forms;
7 |
8 | namespace LicenseGenerator.ViewModel
9 | {
10 | public class ClientModel : ViewModel
11 | {
12 | private string _email;
13 | private DateTime _date;
14 | private string _macAddress;
15 | private string _publicKey;
16 | private string _license;
17 |
18 | public string Email
19 | {
20 | get => _email;
21 | set => SetProperty(ref _email, value);
22 | }
23 |
24 | public DateTime Date
25 | {
26 | get => _date;
27 | set => SetProperty(ref _date, value);
28 | }
29 |
30 | public string MACAddress
31 | {
32 | get => _macAddress;
33 | set => SetProperty(ref _macAddress, value);
34 | }
35 |
36 | public string PublicKey
37 | {
38 | get => _publicKey;
39 | set => SetProperty(ref _publicKey, value);
40 | }
41 |
42 | public string License
43 | {
44 | get => _license;
45 | set => SetProperty(ref _license, value);
46 | }
47 |
48 | ///
49 | /// 获取本机MAC地址
50 | ///
51 | public void GetMACAddress()
52 | {
53 | MACAddress = NetworkInterface
54 | .GetAllNetworkInterfaces()
55 | .Where(nic =>
56 | nic.OperationalStatus == OperationalStatus.Up &&
57 | nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
58 | .Select(nic => nic.GetPhysicalAddress().ToString())
59 | .FirstOrDefault();
60 | }
61 |
62 | ///
63 | /// 激活授权
64 | ///
65 | public void ActivateLicense()
66 | {
67 | // 导入公钥
68 | // 公钥不能让用户输入,否则用户可以用自己的密钥伪造信息和签名通过验证
69 | var rsa = new RSACryptoServiceProvider();
70 | try
71 | {
72 | rsa.ImportFromPem(PublicKey.AsSpan());
73 | }
74 | catch (ArgumentException)
75 | {
76 | MessageBox.Show("公钥错误!");
77 | return;
78 | }
79 |
80 | // 对激活码进行解码
81 | byte[] licenseDecode;
82 | try
83 | {
84 | licenseDecode = Convert.FromBase64String(License);
85 | }
86 | catch (Exception e) when (e is FormatException or ArgumentNullException)
87 | {
88 | MessageBox.Show("激活码错误!请检查激活码后重试");
89 | return;
90 | }
91 |
92 | // 头两个字节是授权信息的长度
93 | var dataLen = (licenseDecode[0] << 8) + licenseDecode[1];
94 | // 授权信息
95 | var data = licenseDecode[2..(dataLen + 2)];
96 | // 授权信息的签名
97 | var dataSigned = licenseDecode[(dataLen + 2)..];
98 | // 验证签名与原始信息是否匹配
99 | if (!rsa.VerifyData(data, new SHA1CryptoServiceProvider(), dataSigned))
100 | {
101 | MessageBox.Show("激活码错误!请检查激活码后重试");
102 | return;
103 | }
104 |
105 | // 激活码为真,但还要做输入信息的验证
106 | var dataEntity = JsonSerializer.Deserialize(data, typeof(ClientModel)) as ClientModel;
107 | if (dataEntity?.Email != Email || dataEntity?.MACAddress != MACAddress)
108 | {
109 | MessageBox.Show("激活码与本机或输入信息不匹配!");
110 | return;
111 | }
112 |
113 | if (dataEntity?.Date < DateTime.Now)
114 | {
115 | MessageBox.Show("激活码已过期!请重新购买");
116 | return;
117 | }
118 |
119 | MessageBox.Show(@$"激活成功,授权给{dataEntity?.Email},有效日期至{dataEntity?.Date.ToShortDateString()}");
120 | }
121 | }
122 | }
--------------------------------------------------------------------------------
/View/ClientForm.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace LicenseGenerator.View
3 | {
4 | partial class ClientForm
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Windows Form Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.grpInfo = new System.Windows.Forms.GroupBox();
33 | this.btnActivate = new System.Windows.Forms.Button();
34 | this.tbLicense = new System.Windows.Forms.TextBox();
35 | this.lblLicense = new System.Windows.Forms.Label();
36 | this.tbPublicKey = new System.Windows.Forms.TextBox();
37 | this.lblPublicKey = new System.Windows.Forms.Label();
38 | this.tbMAC = new System.Windows.Forms.TextBox();
39 | this.lblMAC = new System.Windows.Forms.Label();
40 | this.tbEmail = new System.Windows.Forms.TextBox();
41 | this.lblEmail = new System.Windows.Forms.Label();
42 | this.grpInfo.SuspendLayout();
43 | this.SuspendLayout();
44 | //
45 | // grpInfo
46 | //
47 | this.grpInfo.Controls.Add(this.btnActivate);
48 | this.grpInfo.Controls.Add(this.tbLicense);
49 | this.grpInfo.Controls.Add(this.lblLicense);
50 | this.grpInfo.Controls.Add(this.tbPublicKey);
51 | this.grpInfo.Controls.Add(this.lblPublicKey);
52 | this.grpInfo.Controls.Add(this.tbMAC);
53 | this.grpInfo.Controls.Add(this.lblMAC);
54 | this.grpInfo.Controls.Add(this.tbEmail);
55 | this.grpInfo.Controls.Add(this.lblEmail);
56 | this.grpInfo.Location = new System.Drawing.Point(12, 12);
57 | this.grpInfo.Name = "grpInfo";
58 | this.grpInfo.Size = new System.Drawing.Size(550, 306);
59 | this.grpInfo.TabIndex = 10;
60 | this.grpInfo.TabStop = false;
61 | this.grpInfo.Text = "密钥信息";
62 | //
63 | // btnActivate
64 | //
65 | this.btnActivate.Location = new System.Drawing.Point(435, 262);
66 | this.btnActivate.Name = "btnActivate";
67 | this.btnActivate.Size = new System.Drawing.Size(89, 37);
68 | this.btnActivate.TabIndex = 18;
69 | this.btnActivate.Text = "激活";
70 | this.btnActivate.UseVisualStyleBackColor = true;
71 | this.btnActivate.Click += new System.EventHandler(this.BtnActivate_Click);
72 | //
73 | // tbLicense
74 | //
75 | this.tbLicense.Location = new System.Drawing.Point(335, 27);
76 | this.tbLicense.Multiline = true;
77 | this.tbLicense.Name = "tbLicense";
78 | this.tbLicense.Size = new System.Drawing.Size(189, 229);
79 | this.tbLicense.TabIndex = 17;
80 | //
81 | // lblLicense
82 | //
83 | this.lblLicense.AutoSize = true;
84 | this.lblLicense.Location = new System.Drawing.Point(287, 30);
85 | this.lblLicense.Name = "lblLicense";
86 | this.lblLicense.Size = new System.Drawing.Size(44, 17);
87 | this.lblLicense.TabIndex = 16;
88 | this.lblLicense.Text = "激活码";
89 | //
90 | // tbPublicKey
91 | //
92 | this.tbPublicKey.Location = new System.Drawing.Point(91, 117);
93 | this.tbPublicKey.Multiline = true;
94 | this.tbPublicKey.Name = "tbPublicKey";
95 | this.tbPublicKey.ReadOnly = true;
96 | this.tbPublicKey.Size = new System.Drawing.Size(179, 139);
97 | this.tbPublicKey.TabIndex = 15;
98 | //
99 | // lblPublicKey
100 | //
101 | this.lblPublicKey.AutoSize = true;
102 | this.lblPublicKey.Location = new System.Drawing.Point(26, 120);
103 | this.lblPublicKey.Name = "lblPublicKey";
104 | this.lblPublicKey.Size = new System.Drawing.Size(32, 17);
105 | this.lblPublicKey.TabIndex = 14;
106 | this.lblPublicKey.Text = "公钥";
107 | //
108 | // tbMAC
109 | //
110 | this.tbMAC.Location = new System.Drawing.Point(91, 72);
111 | this.tbMAC.Name = "tbMAC";
112 | this.tbMAC.ReadOnly = true;
113 | this.tbMAC.Size = new System.Drawing.Size(179, 23);
114 | this.tbMAC.TabIndex = 13;
115 | //
116 | // lblMAC
117 | //
118 | this.lblMAC.AutoSize = true;
119 | this.lblMAC.Location = new System.Drawing.Point(25, 75);
120 | this.lblMAC.Name = "lblMAC";
121 | this.lblMAC.Size = new System.Drawing.Size(60, 17);
122 | this.lblMAC.TabIndex = 12;
123 | this.lblMAC.Text = "MAC地址";
124 | //
125 | // tbEmail
126 | //
127 | this.tbEmail.Location = new System.Drawing.Point(91, 27);
128 | this.tbEmail.Name = "tbEmail";
129 | this.tbEmail.Size = new System.Drawing.Size(179, 23);
130 | this.tbEmail.TabIndex = 9;
131 | //
132 | // lblEmail
133 | //
134 | this.lblEmail.AutoSize = true;
135 | this.lblEmail.Location = new System.Drawing.Point(26, 30);
136 | this.lblEmail.Name = "lblEmail";
137 | this.lblEmail.Size = new System.Drawing.Size(32, 17);
138 | this.lblEmail.TabIndex = 8;
139 | this.lblEmail.Text = "邮箱";
140 | //
141 | // ClientForm
142 | //
143 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
144 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
145 | this.ClientSize = new System.Drawing.Size(574, 332);
146 | this.Controls.Add(this.grpInfo);
147 | this.Name = "ClientForm";
148 | this.Text = "客户端";
149 | this.grpInfo.ResumeLayout(false);
150 | this.grpInfo.PerformLayout();
151 | this.ResumeLayout(false);
152 |
153 | }
154 |
155 | #endregion
156 |
157 | private System.Windows.Forms.GroupBox grpInfo;
158 | private System.Windows.Forms.TextBox tbPublicKey;
159 | private System.Windows.Forms.Label lblPublicKey;
160 | private System.Windows.Forms.TextBox tbMAC;
161 | private System.Windows.Forms.Label lblMAC;
162 | private System.Windows.Forms.TextBox tbEmail;
163 | private System.Windows.Forms.Label lblEmail;
164 | private System.Windows.Forms.TextBox tbLicense;
165 | private System.Windows.Forms.Label lblLicense;
166 | private System.Windows.Forms.Button btnActivate;
167 | }
168 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/View/GeneratorForm.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace LicenseGenerator.View
3 | {
4 | partial class GeneratorForm
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Windows Form Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.grpInfo = new System.Windows.Forms.GroupBox();
33 | this.dtpDate = new System.Windows.Forms.DateTimePicker();
34 | this.tbPrivateKey = new System.Windows.Forms.TextBox();
35 | this.lblPrivateKey = new System.Windows.Forms.Label();
36 | this.tbMAC = new System.Windows.Forms.TextBox();
37 | this.lblMAC = new System.Windows.Forms.Label();
38 | this.lblDate = new System.Windows.Forms.Label();
39 | this.tbEmail = new System.Windows.Forms.TextBox();
40 | this.lblEmail = new System.Windows.Forms.Label();
41 | this.grpLicense = new System.Windows.Forms.GroupBox();
42 | this.btnGenerate = new System.Windows.Forms.Button();
43 | this.tbLicense = new System.Windows.Forms.TextBox();
44 | this.grpInfo.SuspendLayout();
45 | this.grpLicense.SuspendLayout();
46 | this.SuspendLayout();
47 | //
48 | // grpInfo
49 | //
50 | this.grpInfo.Controls.Add(this.dtpDate);
51 | this.grpInfo.Controls.Add(this.tbPrivateKey);
52 | this.grpInfo.Controls.Add(this.lblPrivateKey);
53 | this.grpInfo.Controls.Add(this.tbMAC);
54 | this.grpInfo.Controls.Add(this.lblMAC);
55 | this.grpInfo.Controls.Add(this.lblDate);
56 | this.grpInfo.Controls.Add(this.tbEmail);
57 | this.grpInfo.Controls.Add(this.lblEmail);
58 | this.grpInfo.Location = new System.Drawing.Point(12, 12);
59 | this.grpInfo.Name = "grpInfo";
60 | this.grpInfo.Size = new System.Drawing.Size(296, 334);
61 | this.grpInfo.TabIndex = 9;
62 | this.grpInfo.TabStop = false;
63 | this.grpInfo.Text = "密钥信息";
64 | //
65 | // dtpDate
66 | //
67 | this.dtpDate.Location = new System.Drawing.Point(91, 72);
68 | this.dtpDate.Name = "dtpDate";
69 | this.dtpDate.Size = new System.Drawing.Size(179, 23);
70 | this.dtpDate.TabIndex = 16;
71 | //
72 | // tbPrivateKey
73 | //
74 | this.tbPrivateKey.Location = new System.Drawing.Point(26, 185);
75 | this.tbPrivateKey.Multiline = true;
76 | this.tbPrivateKey.Name = "tbPrivateKey";
77 | this.tbPrivateKey.Size = new System.Drawing.Size(244, 132);
78 | this.tbPrivateKey.TabIndex = 15;
79 | //
80 | // lblPrivateKey
81 | //
82 | this.lblPrivateKey.AutoSize = true;
83 | this.lblPrivateKey.Location = new System.Drawing.Point(26, 165);
84 | this.lblPrivateKey.Name = "lblPrivateKey";
85 | this.lblPrivateKey.Size = new System.Drawing.Size(32, 17);
86 | this.lblPrivateKey.TabIndex = 14;
87 | this.lblPrivateKey.Text = "私钥";
88 | //
89 | // tbMAC
90 | //
91 | this.tbMAC.Location = new System.Drawing.Point(91, 117);
92 | this.tbMAC.Name = "tbMAC";
93 | this.tbMAC.Size = new System.Drawing.Size(179, 23);
94 | this.tbMAC.TabIndex = 13;
95 | //
96 | // lblMAC
97 | //
98 | this.lblMAC.AutoSize = true;
99 | this.lblMAC.Location = new System.Drawing.Point(26, 120);
100 | this.lblMAC.Name = "lblMAC";
101 | this.lblMAC.Size = new System.Drawing.Size(60, 17);
102 | this.lblMAC.TabIndex = 12;
103 | this.lblMAC.Text = "MAC地址";
104 | //
105 | // lblDate
106 | //
107 | this.lblDate.AutoSize = true;
108 | this.lblDate.Location = new System.Drawing.Point(26, 75);
109 | this.lblDate.Name = "lblDate";
110 | this.lblDate.Size = new System.Drawing.Size(56, 17);
111 | this.lblDate.TabIndex = 10;
112 | this.lblDate.Text = "有效日期";
113 | //
114 | // tbEmail
115 | //
116 | this.tbEmail.Location = new System.Drawing.Point(91, 27);
117 | this.tbEmail.Name = "tbEmail";
118 | this.tbEmail.Size = new System.Drawing.Size(179, 23);
119 | this.tbEmail.TabIndex = 9;
120 | //
121 | // lblEmail
122 | //
123 | this.lblEmail.AutoSize = true;
124 | this.lblEmail.Location = new System.Drawing.Point(26, 30);
125 | this.lblEmail.Name = "lblEmail";
126 | this.lblEmail.Size = new System.Drawing.Size(32, 17);
127 | this.lblEmail.TabIndex = 8;
128 | this.lblEmail.Text = "邮箱";
129 | //
130 | // grpLicense
131 | //
132 | this.grpLicense.Controls.Add(this.btnGenerate);
133 | this.grpLicense.Controls.Add(this.tbLicense);
134 | this.grpLicense.Location = new System.Drawing.Point(315, 13);
135 | this.grpLicense.Name = "grpLicense";
136 | this.grpLicense.Size = new System.Drawing.Size(200, 333);
137 | this.grpLicense.TabIndex = 10;
138 | this.grpLicense.TabStop = false;
139 | this.grpLicense.Text = "激活码";
140 | //
141 | // btnGenerate
142 | //
143 | this.btnGenerate.Location = new System.Drawing.Point(41, 279);
144 | this.btnGenerate.Name = "btnGenerate";
145 | this.btnGenerate.Size = new System.Drawing.Size(126, 37);
146 | this.btnGenerate.TabIndex = 17;
147 | this.btnGenerate.Text = "生成";
148 | this.btnGenerate.UseVisualStyleBackColor = true;
149 | this.btnGenerate.Click += new System.EventHandler(this.BtnGenerate_Click);
150 | //
151 | // tbLicense
152 | //
153 | this.tbLicense.Location = new System.Drawing.Point(18, 22);
154 | this.tbLicense.Multiline = true;
155 | this.tbLicense.Name = "tbLicense";
156 | this.tbLicense.Size = new System.Drawing.Size(165, 251);
157 | this.tbLicense.TabIndex = 16;
158 | //
159 | // GeneratorForm
160 | //
161 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
162 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
163 | this.ClientSize = new System.Drawing.Size(526, 358);
164 | this.Controls.Add(this.grpLicense);
165 | this.Controls.Add(this.grpInfo);
166 | this.Name = "GeneratorForm";
167 | this.Text = "激活码生成器";
168 | this.grpInfo.ResumeLayout(false);
169 | this.grpInfo.PerformLayout();
170 | this.grpLicense.ResumeLayout(false);
171 | this.grpLicense.PerformLayout();
172 | this.ResumeLayout(false);
173 |
174 | }
175 |
176 | #endregion
177 |
178 | private System.Windows.Forms.GroupBox grpInfo;
179 | private System.Windows.Forms.DateTimePicker dtpDate;
180 | private System.Windows.Forms.TextBox tbPrivateKey;
181 | private System.Windows.Forms.Label lblPrivateKey;
182 | private System.Windows.Forms.TextBox tbMAC;
183 | private System.Windows.Forms.Label lblMAC;
184 | private System.Windows.Forms.Label lblDate;
185 | private System.Windows.Forms.TextBox tbEmail;
186 | private System.Windows.Forms.Label lblEmail;
187 | private System.Windows.Forms.GroupBox grpLicense;
188 | private System.Windows.Forms.Button btnGenerate;
189 | private System.Windows.Forms.TextBox tbLicense;
190 | }
191 | }
192 |
193 |
--------------------------------------------------------------------------------