mirror of
https://github.com/junian/Standard.Licensing.git
synced 2026-04-25 05:45:51 +03:00
[PR #16] [CLOSED] Add License Keys Using .Net Cryptography APIs to project #43
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/Standard.Licensing#43
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/junian/Standard.Licensing/pull/16
Author: @ConnerPhillis
Created: 4/30/2020
Status: ❌ Closed
Base:
master← Head:master📝 Commits (2)
2aa9260commit for LicenseKey codeb7ca62badd readme📊 Changes
24 files changed (+1942 additions, -2 deletions)
View changed files
➕
src/Standard.Licensing.LicenseKey.Tests/Extensions/TestExtensions.cs(+6 -0)➕
src/Standard.Licensing.LicenseKey.Tests/KeyGeneration/StandardLicenseFactoryTests.cs(+82 -0)➕
src/Standard.Licensing.LicenseKey.Tests/KeyValidation/StandardLicenseValidatorTests.cs(+544 -0)➕
src/Standard.Licensing.LicenseKey.Tests/LicenseKeyTests.cs(+36 -0)➕
src/Standard.Licensing.LicenseKey.Tests/LifecycleTests.cs(+93 -0)➕
src/Standard.Licensing.LicenseKey.Tests/SignedLicenseTests.cs(+34 -0)➕
src/Standard.Licensing.LicenseKey.Tests/Standard.Licensing.LicenseKey.csproj(+22 -0)➕
src/Standard.Licensing.LicenseKey.Tests/TestLicenseKeyManager.cs(+40 -0)➕
src/Standard.Licensing.LicenseKey.Tests/TestLicenses/SimpleTestLicense.cs(+34 -0)➕
src/Standard.Licensing.LicenseKey/Internals/Extensions/JsonExtensions.cs(+23 -0)➕
src/Standard.Licensing.LicenseKey/Jwt/JwtTokenManager.cs(+90 -0)➕
src/Standard.Licensing.LicenseKey/KeyGeneration/ILicenseFactory.cs(+49 -0)➕
src/Standard.Licensing.LicenseKey/KeyGeneration/StandardLicenseFactory.cs(+49 -0)➕
src/Standard.Licensing.LicenseKey/KeyValidation/ILicenseValidator.cs(+181 -0)➕
src/Standard.Licensing.LicenseKey/KeyValidation/LicenseValidationResults.cs(+14 -0)➕
src/Standard.Licensing.LicenseKey/KeyValidation/StandardLicenseValidator.cs(+234 -0)➕
src/Standard.Licensing.LicenseKey/LicenseKey.cs(+60 -0)➕
src/Standard.Licensing.LicenseKey/LicenseKeyManager.cs(+28 -0)➕
src/Standard.Licensing.LicenseKey/LicenseSigningParameters.cs(+126 -0)➕
src/Standard.Licensing.LicenseKey/LicenseType.cs(+10 -0)...and 4 more files
📄 Description
This code is a massive effort I've been working on in spare time over the last few months for a school project. There is a readme attached in the PR detailing the new API that I have created for this repository.
Here's the contents of the Readme as they exist now.
Usage
Creating License Signing Parameters
StandardLicensing License Keys uses .Net's Cryptology APIs to create and sign the license keys it generates, more specifically, the
RsaSsaPssSha256algorithm. Keys can be any length in bits that the RSA algorithm permits (512, 1024, 3096, etc...). The default is 2048 bits.Generating New License Parameters
You can generate new keys for license signing by instantiating the
LicenseSigningParameterswith no arguments or one argument representing your desired key size.Saving License Parameters
If you wish to store your public key in your application or simply wish to use the same private key for every new license you generate you will have to save your license parameters. This can be accomplished easily with the
ExportandImportmethods which also support asynchronous code.Creating the License Generator
StandardLicensing License Keys supports a base set of fields for licenses, but also has functionality to support further configuration through generics. This allows you to specify further strongly typed license details in the
KeyDataproperty.Using the Fluent API
StandardLicensing License Keys also supports a fluent API to configure all of its license properties.
Using Standard Assignments
If you do not want to use the fluent API for creation you can call
CreateLicenseon theILicenseFactoryinterface and manipulate the license with standard assignments, then sign the license later on with theSignmethod. Example:Once you have generated the license then you are free to transport it anywhere. So long as the public key is present the validator should be able to check its contents.
Validate The License in Your Application
The license data can be stored however you please, however once you start to validate the license you must reconstruct the
SignedLicenseobject that the license was originally exported as. This class only consists of two fields,PublicKeyandLienseDataso this is not hard to do.once you have the
SignedLicenseobject, you can use the license validation API to validate your license.StandardLicensing License Keys will not throw any exceptions unless it fails to authenticate the license with its public key.
All errors will be put in the
Errorsproperty on theLicenseValidationResults<T>class and the user will be able to enumerate them manually. This class also exposes the physical license in theLicenseKeyproperty, so license values can be read after validation.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.