Portable.Licensing how to tie a license to a PC

妖精的绣舞 提交于 2019-12-09 16:35:57

问题


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?


回答1:


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", "john.doe@yourmail.here")  
    .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




回答2:


You can call AsserThat method:

license.Validate()
.AssertThat(lic => lic.ProductFeatures.Get("HardwareId") == "133456", new GeneralValidationFailure() { Message="Invalid Hardware.", HowToResolve="Contact administrator"});



回答3:


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.



来源:https://stackoverflow.com/questions/30587116/portable-licensing-how-to-tie-a-license-to-a-pc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!