We have a C# application and need to protect it against illegal copying. So we decided to use the Portable.Licensing
library to protect our system.
How I can tie a license to hardware id in Portable.Licensing
, so that only a specific PC can use license?
Use ProtectedData.Protect with DataProtectionScope.LocalMachine to encrypt some key value pair in the licence file. Then the Licence is valid only if that value can be successfully decrypted on the same machine.
ProtectedData.UnProtect will only decrypt on the same machine it was encrypted. This will require desktop/client server interaction during the registration process to implement though.
You can call AsserThat
method:
license.Validate()
.AssertThat(lic => lic.ProductFeatures.Get("HardwareId") == "133456", new GeneralValidationFailure() { Message="Invalid Hardware.", HowToResolve="Contact administrator"});
You can generate a unique hash over the PC's name, hardware information, etc. and add this hash as Additional Attribute
during the license creation.
Example of license creation:
var license = License.New()
.WithUniqueIdentifier(Guid.NewGuid())
.As(LicenseType.Standard)
.WithMaximumUtilization(1)
.WithAdditionalAttributes(new Dictionary<string, string>
{
{"HardwareId", "........"}
})
.LicensedTo("John Doe", "[email protected]")
.CreateAndSignWithPrivateKey(privateKey, passPhrase);
To validate the attribute you can implement your own validation extension method or just use the existing AssertThat()
. Example: [1]
The generation of a unique hardware id is out of the scope of portable licensing.
[1] https://github.com/dnauck/Portable.Licensing/blob/develop/src/Portable.Licensing/Validation/LicenseValidationExtensions.cs#L100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With