Portable.Licensing如何将许可证绑定到PC
我们有一个C#应用程序,需要保护它免受非法复制。 所以我们决定使用Portable.Licensing
库来保护我们的系统。
我如何将许可证绑定到Portable.Licensing
硬件ID,以便只有特定的PC可以使用许可证?
您可以在PC的名称,硬件信息等上生成唯一的哈希值,并在创建许可证期间将此哈希值添加为“ Additional Attribute
”。
许可证创建示例:
var license = License.New() .WithUniqueIdentifier(Guid.NewGuid()) .As(LicenseType.Standard) .WithMaximumUtilization(1) .WithAdditionalAttributes(new Dictionary { {"HardwareId", "........"} }) .LicensedTo("John Doe", "john.doe@yourmail.here") .CreateAndSignWithPrivateKey(privateKey, passPhrase);
要validation属性,您可以实现自己的validation扩展方法,或者只使用现有的AssertThat()
。 示例:[1]
生成唯一的硬件ID超出了便携式许可的范围。
你可以调用AsserThat
方法:
license.Validate() .AssertThat(lic => lic.ProductFeatures.Get("HardwareId") == "133456", new GeneralValidationFailure() { Message="Invalid Hardware.", HowToResolve="Contact administrator"});
将ProtectedData.Protect与DataProtectionScope.LocalMachine一起使用以加密许可证文件中的某些键值对。 然后,只有在同一台计算机上成功解密该值时,许可证才有效。
ProtectedData.UnProtect只会在加密的同一台机器上解密。 这将需要在注册过程中实现桌面/客户端服务器交互来实现。