Get Demo
  • Windows
  • MacOS
  • Linux

.NET-version


Description

The .NET version of the key generator is a build that contains everything required to generate serial numbers. The source code is located in %Examples%\Keygen\Net as two projects: KeyGen (the key generator itself) and Usage (an example of how to use the key generator).

The key generator is provided as source code for quick building under a specific version of the .NET Framework. However, we strongly recommend not modifying the code. In future versions of VMProtect, new features may be added to the generator, which could require changes to the code. Modifying it may also introduce errors that are difficult to detect. If you find issues in the original generator code or would like to suggest improvements, please contact the support team.

Using the generator

Use the code from the Usage project as a base, then add a reference to the VMProtect.KeyGen.dll assembly in your project. After that, you will be able to generate serial numbers in your application.

For correct operation, the generator must “know” for which product it is generating serial numbers. To achieve this, open the “Project | Export key pair” dialog in VMProtect and select the “Parameters for KeyGen.Net” option. The text field below will contain data that you must copy and paste into your application as a string constant.

Here is an example of how to call the generator:

try
{
        string data = @""; // put the exported data here
        Generator g = new Generator(data);
        g.UserName = "John Doe";
        g.EMail = "john@doe.com";
        g.ExpirationDate = DateTime.Now.AddMonths(1);
        g.MaxBuildDate = DateTime.Now.AddYears(1);
        g.RunningTimeLimit = 15;
        g.HardwareID = "AQIDBAgHBgU=";
        g.UserData = new byte[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
        string serial = g.Generate();
        Console.WriteLine("Serial number:\n{0}\n", serial);
}
catch (Exception ex)
{
        Console.WriteLine("Error: {0}", ex);
}

The string copied from VMProtect should be placed into the data variable passed to the serial number class constructor. If any problems occur while parsing the product data, the constructor throws an exception containing a description of the issue. If the constructor completes successfully, the generator is ready to produce serial numbers.

A serial number can contain various types of information specified through generator properties. The example above shows how to populate all available fields. Some fields have limitations. For example, User Name and E-Mail cannot exceed 255 UTF-8 characters. If invalid data is provided, the corresponding properties will throw exceptions with a description of the problem.

Once the generator is configured, the Generate() method is called. This method generates the serial number. At this stage, all serial number data are combined, the checksum is calculated, and the data are encrypted. If the data size exceeds the allowed limit, the method throws an exception.

If you need to generate multiple serial numbers, you can reuse the generator instance multiple times without recreating it. To reset any property of the generator, simply assign it a null value.

Last updated 11 days ago