
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
ThinkSharp.Licensing
Advanced tools
Simple library with fluent API for creating and verifying signed licenses
ThinkSharp.Licensing is a simple library with fluent API for creating and verifying signed licenses. It provides the following functionallities:
ThinkSharp.Licensing can be installed via Nuget
Install-Package ThinkSharp.Licensing
The class SignedLicense
encapsulates some license related information and a signature for verifying it. The license can be serialized / deserialized for storing it on the client. It has following public properties:
DateTime.MaxValue
for licenses without expiration)SerialNumber
below)IDictionary<string, string>
with custom key value pairsThe static Lic
class is the entry point for the fluent API that allows to work with signed licenses. It has the following static properties:
Create signed licenses
SignedLicense license = Lic.Builder
.WithRsaPrivateKey(pk) // .WithSigner(ISigner)
.WithHardwareIdentifier(HardwareIdentifier.ForCurrentComputer()) // .WithoutHardwareIdentifier()
.WithSerialNumber(SerialNumber.Create("ABC")) // .WithoutSerialNumber()
.WithoutExpiration() // .ExpiresIn(TimeSpan), .ExpiresOn(DateTime)
.WithProperty("Name", "Bill Gates")
.WithProperty("Company", "Microsoft") //... other key value pairs
.SignAndCreate();
Serialize License
The SignedLicense
can be serialized as encrypted base64 encoded string (default):
var encryptedText = license.Serialize();
// FW9JbxVRYW8hcWBVZ3VHbGosEBxfYhlMZmshHHUxGBVbHBksc3
// 9EHywLc2NNaWIsE39YaAxFbXo7BhhSYxwhZmBJYSAGGxkuEhUj
// GREwFw08GxsxEBc8GywLER8jGBAuGRQ1EgEzExc5Ehs0GSAGZU
// BsRRdOQk1tAGptX0RyLSdPRExxQUN1EWxoQ19jWE5nVCAGahJm
// Ek8/GhFwSwY7ehk3Sm4+cRk4EFh4GVkydFh0U0NURAZUWBVnbW
// 9eXQ5JTWtgElI4cHxaBFtEQ2ZBGlFiSmR5bWsuEHRfAENAYx8+
// U09vQmM+Tg5SakFmcmxKFWM9YQ4yR2NVSVdidUwnE1BuS0BLeX
// tbU0tifnNDQ25teVZjcXl2H2pQVnk7QEBTC19FXFRGeGs6T1FX
// SUR0YmprFmknHRA5VBpOeUdYHQ==
or as plain text string:
var plainText = license.SerializePlainText();
// 5BED5GAB-E5TGXKGK-01SI8MFF-7T099W78-SRH4
// SNABC-3RTC-DMW7-9SC1-MAHA
// 08/28/2017 00:00:00
// 12/31/9999 23:59:59
// Name:Bill Gates
// Company:Microsoft
// A3g2b310qk+7Q86jC2Z890ut2x3TuxxbUd+Xs4fMBRv/HmFl9s
// 9PQV/zEcKM1pcjIuFJ/0YS+bAC22xnnbN2e/SJljYMK5N1J/3g
// NYbvcUa+8qokmGRZZsfnURBcCaRwbQTz4KQvT7kaR+rIwuGXF6
// dpViixIKj6D+618t7BRfY=
Verify License
For deserializing the license, the Lic.Verifier
has to be used. If the license can not be deserialized hor has no valid signature, an exception is thrown.
SignedLicense license = Lic.Verifier
.WithRsaPublicKey(publicKey) // .WithSigner(ISigner)
.WithApplicationCode("ABC") // .WithoutApplicationCode
.LoadAndVerify(licenseText);
Create public/private key Pair
A public and private key pair can be generated using the Lic.KeyGenerator
object:
SigningKeyPair pair = Lic.KeyGenerator.GenerateRsaKeyPair();
Console.WriteLine(pair.PrivateKey);
Console.WriteLine(pair.PublicKey);
The hardware identifier is an identifier that derives from 4 characteristics of the computer's hardware (processor ID, serial number of BIOS and so on). The identifier may look like:
5BED5GAB-E5TGXKGK-01SI8MFF-7T099W78-SRH4
Each characteristic is encoded in one of first 4 parts (8 charachters). The hardware identifier will be accepted if at least 2 of the 4 characteristics are equal. That ensures, that the license doesn't become invalid if e.g. the processor of the computer changed. The last part (4 characters) is a check sum that can be used to detect errors in the the hardware identifier.
// Create:
string hardwareIdentifier = HardwareIdentifier.ForCurrentComputer();
// Validate Checksum
if (!HardwareIdentifier.IsCheckSumValid(hardwareIdentifier))
{
Console.WriteLine("Entered hardware identifier has errors.");
}
// Validate for current computer
if (!HardwareIdentifier.IsValidForCurrentComputer(hardwareIdentifier))
{
Console.WriteLine("Entered license is not valid for this computer.");
}
A serial number is an identifier with an alpha-numeric application code (3 character), some random characters and a check sum. It looks like SNXXX-YYYY-YYYY-YYYY-ZZZ where XXX is the application code, YYYY is the random part and ZZZ is the check sum. E.g.:
SNABC-D156-KYJF-C4M5-1H96
// ABC = application code
string serialNumber = SerialNumber.Create("ABC");
// Validate CheckSum
if (!SerialNumber.IsCheckSumValid(serialNumber))
{
Console.WriteLine("Entered serial number is not valid.");
}
ThinkSharp.Licensing is released under The MIT license (MIT)
We use SemVer for versioning. For the versions available, see the tags on this repository.
Thanks to Peter-B- for simplifying the project structure and improving compatibility to .Net 5.0.
If you like ThinkSharp.Licensing and use it in your project(s), feel free to give me a cup of coffee :)
FAQs
Simple library with fluent API for creating and verifying signed licenses
We found that thinksharp.licensing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.