原文:.net reactor 学习系列(三)---.net reactor代码自动操作相关保护功能

        接上篇,上篇已经学习了界面的各种功能以及各种配置,这篇准备学习下代码控制许可证。

        代码控制许可证的意思就是软件经过.net reactor保护后,到期时客户端就需要购买许可证,这时软件开发商就需要生成许可证等操作,这个操作可以由代码控制来达到自动化的效果。当然不仅仅是生成操作,还包扩获取许可证的信息,作废许可证,激活许可证等操作。

        在安装目录下...\.NET Reactor\SDK\Binaries文件夹下可以找到License.dll和LicenseGen.dll(.net编写 .net reactor是一个.net 编写的程序)。其中License.dll主要用于获取许可证信息,作废许可证,激活许可证等,可整合到软件项目中,而LicenseGen.dll主要用于生成许可证,不可整合,可以用于许可证自动生成的服务。

        首先看下许可证生成代码:

        /// <summary>
/// 创建许可证
/// </summary>
/// <param name="project_filename"></param>
private void CreateLicenseFile()
{
LicenseGenerator licensegen = new LicenseGenerator();
licensegen.AddAdditonalLicenseInformation("Company", "Eye");
licensegen.Hardware_Enabled = true;
licensegen.HardwareID = "1234-1234-1234-1234-1234";
licensegen.CreateLicenseFile(@"C:\newlicense.license");
}

         这将会在c盘下生成newlicense.license许可证文件,文件的内容包括添加进去的键值对Company-Eye,开启硬件锁,此许可证只针对硬件编码为1234-1234-1234-1234-1234的机器有效。

        再来看看License.dll的功能:

        /// <summary>
/// 许可证是否可用
/// </summary>
/// <returns></returns>
private bool IsValidLicenseAvailable()
{
return License.Status.Licensed;
} /// <summary>
/// 获取许可证键值信息
/// </summary>
private string ReadAdditonalLicenseInformation()
{
string rtnStr = string.Empty;
if (License.Status.Licensed)
{
for (int i = 0; i < License.Status.KeyValueList.Count; i++)
{
string key = License.Status.KeyValueList.GetKey(i).ToString();
string value = License.Status.KeyValueList.GetByIndex(i).ToString(); rtnStr += key + "-" + value + Environment.NewLine;
}
}
return rtnStr;
} /// <summary>
/// 获取软件锁定信息
/// </summary>
/// <returns></returns>
private string ReadLockMsg()
{
string rtnStr = string.Empty;
//使用持续时间锁
bool lock_enabled = License.Status.Evaluation_Lock_Enabled;
License.EvaluationType ev_type = License.Status.Evaluation_Type;
int time = License.Status.Evaluation_Time;
int time_current = License.Status.Evaluation_Time_Current;
rtnStr += string.Format("是否开启持续时间锁:{0},规定使用最大持续时间{1},现在使用时间{2}\n",lock_enabled.ToString(),time.ToString(),time_current.ToString()); //到期锁
bool lock_enabled1 = License.Status.Expiration_Date_Lock_Enable;
System.DateTime expiration_date = License.Status.Expiration_Date;
rtnStr += string.Format("是否开启到期锁:{0},到期时间{1}\n", lock_enabled1.ToString(), expiration_date.ToShortTimeString()); //使用次数锁
bool lock_enabled2 = License.Status.Number_Of_Uses_Lock_Enable;
int max_uses = License.Status.Number_Of_Uses;
int current_uses = License.Status.Number_Of_Uses_Current;
rtnStr += string.Format("是否开启使用次数锁:{0},最大使用次数{1},当前使用次数{2}\n", lock_enabled2.ToString(), max_uses.ToString(), current_uses.ToString()); //并发运行锁
bool lock_enabled3 = License.Status.Number_Of_Instances_Lock_Enable;
int max_instances = License.Status.Number_Of_Instances;
rtnStr += string.Format("是否限制并行数量:{0},最大并行数量:{1}\n", lock_enabled3, max_instances.ToString()); //硬件锁
bool lock_enabled4 = License.Status.Hardware_Lock_Enabled;
string lic_hardware_id = "";
if (lock_enabled)
{
lic_hardware_id = License.Status.License_HardwareID;
}
rtnStr += string.Format("证书是否开启硬件锁{0},对于特定硬件的有效{1}\n", lock_enabled4.ToString(), lic_hardware_id);
return rtnStr;
} /// <summary>
/// 获取机器硬件编号
/// </summary>
/// <returns></returns>
private string GetHardwareID()
{
return License.Status.HardwareID;
} /// <summary>
/// 获取许可证适用的硬件编码
/// </summary>
/// <returns></returns>
private string GetLicenseHardwareID()
{
return License.Status.License_HardwareID;
} /// <summary>
/// 作废许可证
/// </summary>
private string InvalidateLicense()
{
string confirmation_code = License.Status.InvalidateLicense();
return confirmation_code;
} /// <summary>
/// 检查作废许可证的验证码是否有效
/// </summary>
/// <param name="confirmation_code"></param>
/// <returns></returns>
public bool CheckConfirmationCode(string confirmation_code)
{
return License.Status.CheckConfirmationCode(License.Status.HardwareID,
confirmation_code);
} /// <summary>
/// 重新激活许可证
/// </summary>
/// <param name="reactivation_code"></param>
/// <returns></returns>
public bool ReactivateLicense(string reactivation_code)
{
return License.Status.ReactivateLicense(reactivation_code);
}

        其中作废许可证及激活许可证的主要应用场景是:如果许可证开启硬件锁,客户端想从一个机器移动许可证到另一个机器此时就需要先作废许可证,然后在新机器里重新激活许可证。作废许可证可直接调用即可,但是激活许可证需要打开Tools->LicenseReactivation Tool来根据硬件编码生成激活码,传入即可激活许可证。(这里生成激活码我只找到在工具里可视化操作,在代码中找不到这种方法,所以这个应用场景不太适合许可证全自动化的管理)。

        本文代码下载地址:http://yunpan.cn/cJnMmILrX9Av2 访问密码 2585

        下一篇主要学习下.net reactor的简单应用场景

.net reactor 学习系列(三)---.net reactor代码自动操作相关保护功能的更多相关文章

  1. [转].net reactor 学习系列(三)---.net reactor代码自动操作相关保护功能

    接上篇,上篇已经学习了界面的各种功能以及各种配置,这篇准备学习下代码控制许可证. 代码控制许可证的意思就是软件经过.net reactor保护后,到期时客户端就需要购买许可证,这时软件开发商就需要生成 ...

  2. .net reactor 学习系列(二)---.net reactor界面各功能说明

    原文:.net reactor 学习系列(二)---.net reactor界面各功能说明         安装了.net reactor之后,可以在安装目录下找到帮助文档REACTOR_HELP.c ...

  3. .net reactor 学习系列(一)---.net reactor介绍

    原文:.net reactor 学习系列(一)---.net reactor介绍       学习.net已经一年多了,从语言的编写到框架类库的运用再到.net三大解决方案的了解(WF,WCF,WPF ...

  4. .net reactor 学习系列(四)---.net reactor应用场景

    原文:.net reactor 学习系列(四)---.net reactor应用场景         前面已经学习了.net reactor一些基础知识,现在准备学习下实际的应用场景,只是简单的保护和 ...

  5. [转].net reactor 学习系列(二)---.net reactor界面各功能说明

    安装了.net reactor之后,可以在安装目录下找到帮助文档REACTOR_HELP.chm,目前没有中文版本,里面详细介绍了.net reactor的各功能及使用场景.本系列文章是基于此帮助文档 ...

  6. Spring学习系列(三) 通过Java代码装配Bean

    上面梳理了通过注解来隐式的完成了组件的扫描和自动装配,下面来学习下如何通过显式的配置的装配bean 二.通过Java类装配bean 在前面定义了HelloWorldConfig类,并使用@Compon ...

  7. [转].net reactor 学习系列(四)---.net reactor应用场景

    前面已经学习了.net reactor一些基础知识,现在准备学习下实际的应用场景,只是简单的保护和许可证发放场景.如果想应用更高级的场景比如自动化程序许可证的发放及自定义客户端的过期提示等等就需要自己 ...

  8. RabbitMQ学习系列三-C#代码接收处理消息

    RabbitMQ学习系列三:.net 环境下 C#代码订阅 RabbitMQ 消息并处理 http://www.80iter.com/blog/1438251320680361 http://www. ...

  9. MyBatis学习系列三——结合Spring

    目录 MyBatis学习系列一之环境搭建 MyBatis学习系列二——增删改查 MyBatis学习系列三——结合Spring MyBatis在项目中应用一般都要结合Spring,这一章主要把MyBat ...

随机推荐

  1. Python 奇葩语法

    a = 1, 2, 3 赋值后的结果,a == (1, 2, 3),将一个元组(tuple)赋给了变量 a (1, 2) + (3, ) ⇒ (1, 2, 3),并不能说明 tuple 可以添加新的元 ...

  2. WEB应用图片的格式,以及各自的特点和优化(一) by FungLeo

    WEB应用图片的格式,以及各自的特点和优化(一) by FungLeo 前言 12年前我入行三天.用table布局做了一个非常粗糙的网页.我说了一句话,"网页就是表格加文字加图片,图片分两种 ...

  3. ios开发多线程一:了解-NSOperation的基本使用

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  4. java生成UUID通用唯一识别码 (Universally Unique Identifier) 分类: B1_JAVA 2014-08-22 16:09 331人阅读 评论(0) 收藏

    转自:http://blog.csdn.net/carefree31441/article/details/3998553 UUID含义是通用唯一识别码 (Universally Unique Ide ...

  5. sourceinsight4

    转载 http://bbs.pediy.com/thread-215669.htm 如果你觉得软件有用,请购买正版.发布这个纯属娱乐. 转载请注明出处,谢谢! 仅修改了程序中用于License签名验证 ...

  6. Java NIO学习笔记之基本概念

    一.缓冲区操作 缓冲区,以及缓冲区如何工作,是所有 I/O 的基础.所谓"输入/输出"讲的无非就是把数据移进或移出缓冲区. 进程使用 read( )系统调用,要求其缓冲区被填满.内 ...

  7. Swift开发教程--关于Existing instance variable &#39;_delegate&#39;...的解决的方法

    xcode编译提示问题:Existing instance variable '_delegate' for property 'delegate' with  assign attribute mu ...

  8. Linux网络编程——原始套接字编程

    原始套接字编程和之前的 UDP 编程差不多,无非就是创建一个套接字后,通过这个套接字接收数据或者发送数据.区别在于,原始套接字可以自行组装数据包(伪装本地 IP,本地 MAC),可以接收本机网卡上所有 ...

  9. .netcore consul实现服务注册与发现-集群完整版

    原文:.netcore consul实现服务注册与发现-集群完整版 一.Consul的集群介绍    Consul Agent有两种运行模式:Server和Client.这里的Server和Clien ...

  10. [Django] Get started with Django -- Install python and virtualenv

    Install python3 on MacOS: brew install python3 Come alone with python3, there are also some other to ...