RT.MesWeb.LicenseReader
1.2.0
dotnet add package RT.MesWeb.LicenseReader --version 1.2.0
NuGet\Install-Package RT.MesWeb.LicenseReader -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RT.MesWeb.LicenseReader" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RT.MesWeb.LicenseReader" Version="1.2.0" />
<PackageReference Include="RT.MesWeb.LicenseReader" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RT.MesWeb.LicenseReader --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RT.MesWeb.LicenseReader, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RT.MesWeb.LicenseReader@1.2.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RT.MesWeb.LicenseReader&version=1.2.0
#tool nuget:?package=RT.MesWeb.LicenseReader&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
License 使用说明
安装
dotnet add package RT.MesWeb.LicenseReader
目标框架:net8.0 / net10.0
命名空间:RT.MesWeb.Licenses
配置要求
配置节固定为 License,绑定到 LicenseOptions:
{
"License": {
"LicenseMode": 2,
"LicenseFilePath": "License.lic",
"LicenseFileFolder": "",
"HostSystemFolder": "",
"HostName": "",
"MacAddress": "",
"LicenseContent": ""
}
}
| 配置项 | 默认值 | 说明 |
|---|---|---|
LicenseMode |
2 |
1 加密狗 / 2 文件 / 3 网络(未实现)/ 4 授权秘钥包 |
LicenseFilePath |
License.lic |
模式 2 的授权文件名 |
LicenseFileFolder |
"" |
模式 2 的授权文件目录。本包直接 Path.Combine(LicenseFileFolder, LicenseFilePath),为空时按当前工作目录解析;由 MesLicenseChecker 启动时会自动填充为程序根目录 |
HostSystemFolder |
"" |
Linux 下查找 product_uuid 的根目录,为空时使用 /host-sys/class/dmi/id/product_uuid |
HostName |
"" |
模式 4 必填 |
MacAddress |
"" |
模式 4 必填 |
LicenseContent |
"" |
模式 4 必填:Base64(签名 + 授权内容) |
- 未配置的键保留类型默认值(字符串为空串);模式 4 三项任一为空会在读取时抛
SystemException,提示具体缺少哪一项。 - 模式 3(网络授权)当前未实现,配置为 3 时
LicenseReader构造会抛NotSupportedException。 - 模式常量定义于
RT.MesWeb.Licenses.LicenseOptions(LicenseMode_Dongle/LicenseMode_File/LicenseMode_NetWork/LicenseMode_Body),修改时请同步更新本文。
使用说明
var options = configuration.GetSection("License").Get<LicenseOptions>() ?? new LicenseOptions();
using var reader = new LicenseReader(ProductNames.PRODUCT_NAME_RTMES, options);
DateTime expiration = reader.GetExpirationDate();
uint equipmentCount = reader.GetFeature(1); // 1..5
byte licenseType = reader.GetLicenseType();
productKey为产品名(见ProductNames,对应ProductIds),最长 16 字节,必须非空。readLicenseNow(默认true):为false时构造阶段只保存读取器,首次调用取值方法时才真正读取;三种模式(1/2/4)均支持延迟读取。- 读取失败一律抛异常(
SystemException/KeyNotFoundException/NotSupportedException等),不返回默认值。需要"失败即降级"的调用方请自行捕获,Framework 的MesLicenseUtils就是统一try/catch后返回兜底值的。 LicenseReader实例不是线程安全的(延迟读取无同步),请每次检查新建实例或由调用方加锁。
授权校验机制
- 机器标识
- Windows:主机名 + 物理网卡 MAC(逐个尝试,任意一个匹配即可)。
- Linux:主机名 +
product_uuid。
- 授权文件:
DataContractSerializer序列化的 XML;LicenseContent为Base64(签名 + 授权内容)。 - 验签:RSA PKCS#1 v1.5 + SHA1,签名覆盖
MAC(或 UUID) + 主机名 + 授权内容。 - 解密:AES-CBC/PKCS7;密钥为 MAC(Linux 下为 UUID),盐按
EncryptMode取主机名 / 产品名 / 两者组合;密钥与 IV 由 PBKDF2-SHA1(1000 次迭代)派生。迭代次数与哈希算法必须与历史授权文件保持一致,修改会导致存量授权全部失效。
- 加密狗(模式 1)
- 仅 Windows,依赖 SenseLock 运行库
elitee32.dll/elitee64.dll(按进程位数自动选择)。 - 加密狗是独占设备,包内用进程内锁把
Open → 读取 → Close串行化;同机多进程同时读同一把狗不在保护范围内。
- 仅 Windows,依赖 SenseLock 运行库
- 平台守卫:WMI / 注册表探测只在 Windows 上启用,Linux 直接走
product_uuid分支,不再依赖异常兜底。
常见问题
| 异常信息 | 原因 |
|---|---|
Could not get host name / MAC address / license content from configuration. |
模式 4 对应配置项未填写 |
Invalid license signature. MacAddress:..., HostName:... |
机器标识与授权不匹配(换网卡、改主机名、授权文件拷到别的机器) |
License file '...' does not contain license data. |
授权文件为空或根元素不是 LicenseFile |
License data not found for the specified product. |
授权内容里没有该 productKey 对应的条目 |
Network license mode is not implemented. |
LicenseMode 配置为 3 |
FileNotFoundException(含文件路径) |
LicenseFilePath 指向的文件不存在;注意本包不会自动到程序根目录查找,除非宿主已设置 LicenseFileFolder |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- System.Management (>= 8.0.0 && < 11.0.0)
-
net8.0
- System.Management (>= 8.0.0 && < 11.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RT.MesWeb.LicenseReader:
| Package | Downloads |
|---|---|
|
RT.MesWeb.Framework
Framework for mes system |
GitHub repositories
This package is not used by any popular GitHub repositories.