Home » Support » User Manual » Licensing system » Serial number generators » .Net-version

.Net-version

Description

The .Net-version of the key generator is a build containing all that is required to generate serial numbers. Source codes are in Keygen\Net as two projects: KeyGen (the key generator itself) and Usage (an example of use of the key generator).

The key generator is supplied in source codes for quick building under a given version of the .Net Framework, however we strongly do not recommend to apply any changes to the code. In future versions of VMProtect some new possibilities may be added to the generator, and that may lead to repeated modification of the code. Also, this may lead to errors that are very difficult to locate. If you found errors in the original code of the generator or would like to suggest improvements, please contact the support team.

Using the generator

Take the code from the Usage project as a base, then add to your project a link to the VMProtect.KeyGen.dll build. After that you will be able to generate serial numbers in your application. To function properly, the generator must “know” which product you generate serial numbers for. To achieve this, in VMProtect open the “Project | Export key pair” dialog and select the “Parameters for KeyGen.Net” option. The text area below will contain text information you should copy and paste to your application as a string constant.

Here is an example code 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 you copied from VMProtect should be placed to the data variable passed as a parameter to the serial number class constructor. In case of any problems occur while parsing the product data, the constructor throws an exception containing a description of the problem. If the constructor successfully finishes its work, the generator is ready to produce serial numbers.

A serial number can contain various information specified using the generator properties. The above example displays how to fill all and every field of a serial number. Certain fields have limitations. For example, the User Name and E-Mail cannot accept strings exceeding 255 symbols in the UTF-8 encoding. If incorrect data are supplied, properties throw exceptions containing a description of the problem.

When the generator setup is done, the Generate() method is invoked. This method generates a serial number. At this step, all data of the serial number are combined, the checksum is calculated and the data are encrypted. If the volume of data exceeds the allowed length, the method throws an exception.

If you need to generate multiple serial numbers, you can use the generator class several times in a row, without the need to create it from scratch. To clear any given property of the generator, simply assign a null value to it.