Introduced:
In the past I used to like whether there was a software to help the authorization, it can be very simple to create license, and very easy to verify the license.
This is a very common and public function, but I did not find the right open source software, most of the open source software is more complex, and there are too many features I do not need.
So I created this project and I wanted to make the authorization process simple.
Using code:
Easy License is very simple to use, in order to verify a software, you need the following 3 steps.
1:create a public/private Key.
1234567891011121314151617 |
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
1234567891011121314151617 |
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
123456789101112131415161718192021 |
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 inside there is a tool called Licensetool , you can download the source code, run, see how it is created key, create Licens and verify license.
And the system also has a demo project that can help you.
Git, please help to add a star bar.
Https://github.com/EasyHelper/EasyLicense
Http://git.oschina.net/EasyHelper/EasyLicense
NET License tool, Easylicense!