public override License GetLicense(LicenseContext context,
Type type,
object instance,
bool allowExceptions)
if (context.UsageMode == LicenseUsageMode.Designtime) {
// Creating a special DesigntimeLicense will able you to design your
// control without breaking Visual Studio in the process
return new DesigntimeLicense();
}
byte[] existingSerialKey = getExistingSerial();
// Algorithm can be SHA1CryptoServiceProvider for instance
byte[] data = HashAlgorithm.Create().ComputeHash(
username,
dateRequested,
validUntilDate,
// any other data you would like to validate
);
// todo: also check if licensing period is over here. ;-)
for (int l = 0; l < existingSerialKey.Length; ++l) {
if (existingSerialKey[i] != data[i]) {
if (allowExceptions){
throw new LicenseException(type, instance, "License is invalid");
}
return null;
}
}
// RuntimeLicense can be anything inheriting from License
return new RuntimeLicense();
}
此方法返回自定义 许可证,例如具有与许可相关的属性的许可证,例如 DateTime 表示许可到期的时间。设置此操作不会花费太长时间,它可以在 WinForms 和 ASP.NET 站点上正常工作,并且会阻止(不保证暗示)破坏您的许可的简单尝试。
In C# you can use the Licensing class supplied by Microsoft. A sample is available through the link.
Basically you create a class that inherits from LicenseProvider and type the
as an attribute to your class that you would like to have licensed. In your implementation (MyControlLicenseProvider) you can code the appropriate methods for validating the license to your needs and then have your code call
If license is not null your application/control is licensed.
As Sir Graystar states, no system is fool-proof, and someone with the needed skills could engineer themselves around your validation. Don't spend too many hours implementing a rock hard system, but don't make it to easy to circumvent either. :-)
Using a hash like SHA or one of the MD hash functions and feed them some key data could be used to create a simple validation check. Your validation method could do something in the likes of
public override License GetLicense(LicenseContext context,
Type type,
object instance,
bool allowExceptions)
if (context.UsageMode == LicenseUsageMode.Designtime) {
// Creating a special DesigntimeLicense will able you to design your
// control without breaking Visual Studio in the process
return new DesigntimeLicense();
}
byte[] existingSerialKey = getExistingSerial();
// Algorithm can be SHA1CryptoServiceProvider for instance
byte[] data = HashAlgorithm.Create().ComputeHash(
username,
dateRequested,
validUntilDate,
// any other data you would like to validate
);
// todo: also check if licensing period is over here. ;-)
for (int l = 0; l < existingSerialKey.Length; ++l) {
if (existingSerialKey[i] != data[i]) {
if (allowExceptions){
throw new LicenseException(type, instance, "License is invalid");
}
return null;
}
}
// RuntimeLicense can be anything inheriting from License
return new RuntimeLicense();
}
This method returns a custom License, one that for instance has properties regarding the licensing, like a DateTime for the time when licensing runs out. Setting this up should not take to long, it works well with both WinForms and on ASP.NET sites, and will thwart (with no guarantee implied) a simple attempt to break your licensing.
I have never come across anything like a standard in this. What I would personally do is create a record or something like that which holds all the infomartion about the license and what features are available before the product key is entered, and how long before the trial or whatever expires (this can be tricky as you don't want to compare to the system date as this can be changed by the user). You then want to encrypt this record (maybe by salting and hashing it), so that the features can only be unlocked when a specific product key is entered. You also might want to randomly generate said key, although I would do this in a specific format so that a user can always recognise a product key when they are given one, and don't confuse this with an invoice number or whatever.
Rememeber that no system is fool-proof, and someone on some OS will find a way through somehow. This is probably the reason that I ahve never come across any standards, because no method is fully secure. You just have to do your best with it.
发布评论
评论(2)
在 C# 中,您可以使用 Microsoft 提供的许可类 。可通过链接获取示例。
基本上,您创建一个继承自 LicenseProvider 的类,并将 键入
为您想要获得许可的类的属性。在您的实现 (
MyControlLicenseProvider
) 中,您可以编写适当的方法来根据您的需要验证许可证,然后让您的代码调用如果许可证不为空,则您的应用程序/控件已获得许可。
正如格雷斯塔爵士所说,没有一个系统是万无一失的,具有所需技能的人可以围绕您的验证进行自我设计。不要花费太多时间来实现一个坚如磐石的系统,但也不要让它很容易被规避。 :-)
使用诸如 SHA 之类的哈希或 MD 哈希函数之一并向它们提供一些关键数据可用于创建简单的验证检查。您的验证方法可以执行以下操作:
此方法返回自定义 许可证,例如具有与许可相关的属性的许可证,例如 DateTime 表示许可到期的时间。设置此操作不会花费太长时间,它可以在 WinForms 和 ASP.NET 站点上正常工作,并且会阻止(不保证暗示)破坏您的许可的简单尝试。
In C# you can use the Licensing class supplied by Microsoft. A sample is available through the link.
Basically you create a class that inherits from LicenseProvider and type the
as an attribute to your class that you would like to have licensed. In your implementation (
MyControlLicenseProvider
) you can code the appropriate methods for validating the license to your needs and then have your code callIf license is not null your application/control is licensed.
As Sir Graystar states, no system is fool-proof, and someone with the needed skills could engineer themselves around your validation. Don't spend too many hours implementing a rock hard system, but don't make it to easy to circumvent either. :-)
Using a hash like SHA or one of the MD hash functions and feed them some key data could be used to create a simple validation check. Your validation method could do something in the likes of
This method returns a custom License, one that for instance has properties regarding the licensing, like a DateTime for the time when licensing runs out. Setting this up should not take to long, it works well with both WinForms and on ASP.NET sites, and will thwart (with no guarantee implied) a simple attempt to break your licensing.
我从来没有遇到过类似的标准。我个人会做的是创建一个记录或类似的东西,其中包含有关许可证的所有信息以及输入产品密钥之前可用的功能,以及试用版或其他内容到期之前的时间(这可能很棘手,因为您不这样做)不想与系统日期进行比较,因为用户可以更改它)。然后,您想要加密该记录(可能通过对其进行加盐和散列),以便只有在输入特定的产品密钥时才能解锁这些功能。您可能还想随机生成所述密钥,尽管我会以特定格式执行此操作,以便用户在获得产品密钥时始终可以识别产品密钥,并且不要将其与发票号码或其他内容混淆。
请记住,没有一个系统是万无一失的,某些操作系统上的某人会以某种方式找到解决办法。这可能是我从未遇到过任何标准的原因,因为没有一种方法是完全安全的。你只需要尽力而为。
I have never come across anything like a standard in this. What I would personally do is create a record or something like that which holds all the infomartion about the license and what features are available before the product key is entered, and how long before the trial or whatever expires (this can be tricky as you don't want to compare to the system date as this can be changed by the user). You then want to encrypt this record (maybe by salting and hashing it), so that the features can only be unlocked when a specific product key is entered. You also might want to randomly generate said key, although I would do this in a specific format so that a user can always recognise a product key when they are given one, and don't confuse this with an invoice number or whatever.
Rememeber that no system is fool-proof, and someone on some OS will find a way through somehow. This is probably the reason that I ahve never come across any standards, because no method is fully secure. You just have to do your best with it.