简体   繁体   English

Portable.Licensing如何将许可证绑定到PC

[英]Portable.Licensing how to tie a license to a PC

We have a C# application and need to protect it against illegal copying. 我们有一个C#应用程序,需要保护它免受非法复制。 So we decided to use the Portable.Licensing library to protect our system. 所以我们决定使用Portable.Licensing库来保护我们的系统。

How I can tie a license to hardware id in Portable.Licensing , so that only a specific PC can use license? 我如何将许可证绑定到Portable.Licensing硬件ID,以便只有特定的PC可以使用许可证?

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. 您可以在PC的名称,硬件信息等上生成唯一的哈希值,并在许可证创建期间将此哈希值添加为“ Additional Attribute ”。

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() . 要验证属性,您可以实现自己的验证扩展方法,或者只使用现有的AssertThat() Example: [1] 示例:[1]

The generation of a unique hardware id is out of the scope of portable licensing. 生成唯一的硬件ID超出了便携式许可的范围。

[1] https://github.com/dnauck/Portable.Licensing/blob/develop/src/Portable.Licensing/Validation/LicenseValidationExtensions.cs#L100 [1] https://github.com/dnauck/Portable.Licensing/blob/develop/src/Portable.Licensing/Validation/LicenseValidationExtensions.cs#L100

You can call AsserThat method: 你可以调用AsserThat方法:

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

Use ProtectedData.Protect with DataProtectionScope.LocalMachine to encrypt some key value pair in the licence file. 将ProtectedData.Protect与DataProtectionScope.LocalMachine一起使用以加密许可证文件中的某些键值对。 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. ProtectedData.UnProtect只会在加密的同一台机器上解密。 This will require desktop/client server interaction during the registration process to implement though. 这将需要在注册过程中进行桌面/客户端服务器交互来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM