Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable.Licensing how to tie a license to a PC

Tags:

c#

licensing

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?

like image 703
r.zarei Avatar asked Jun 02 '15 04:06

r.zarei


3 Answers

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.

like image 189
Hugh Avatar answered Dec 12 '22 18:12

Hugh


You can call AsserThat method:

license.Validate()
.AssertThat(lic => lic.ProductFeatures.Get("HardwareId") == "133456", new GeneralValidationFailure() { Message="Invalid Hardware.", HowToResolve="Contact administrator"});
like image 35
Rahul Avatar answered Dec 12 '22 18:12

Rahul


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

like image 43
dna Avatar answered Dec 12 '22 16:12

dna