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

r.z*_*rei 8 c# licensing

我们有一个C#应用程序,需要保护它免受非法复制.所以我们决定使用该Portable.Licensing库来保护我们的系统.

我如何将许可证绑定到硬件ID Portable.Licensing,以便只有特定的PC可以使用许可证?

dna*_*dna 8

您可以在PC的名称,硬件信息等上生成唯一的哈希值,并Additional Attribute在创建许可证期间添加此哈希值.

许可证创建示例:

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);
Run Code Online (Sandbox Code Playgroud)

要验证属性,您可以实现自己的验证扩展方法或仅使用现有方法AssertThat().示例:[1]

生成唯一的硬件ID超出了便携式许可的范围.

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

  • 如何验证? (2认同)

Rah*_*hul 5

您可以调用AsserThat方法:

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