Home » Support » User Manual » The Software Licensing System » Serial number generators » Serial Number Generator For The .Net Platform

Serial Number Generator For The .Net Platform

.Net-version of the serial number generator is an assembly that allows to generate serial numbers according to provided settings. Sources are located at Keygen\Net as a solution with two projects: KeyGen – the generator itself and Usage – example project that uses the generator.

Although, the generator is shipped as a source code, it is not recommended to make any changes in the generator’s assembly. The main purpose of source code shipment is an ability to build the generator for various versions of .Net Framework. Any modifications may lead to errors and incompatibles that are hard to find, so if you feel that the generator should be changed, please contact us. If your reasons are serious, we will do this for you, so everybody win as a result.

Using generator

You should start using the code from the Usage project. Copy it to your project and add reference to VMProtect.KeyGen.dll assembly. After that you will be able to generate serial numbers. Before you start, you should init the generator with the information about the product you are going to build serial numbers for. You need to export this information from the “Licenses” page of VMProtect. Press the “Export” button above the licenses list and select “KeyGen.Net” format from the drop down list. Then copy the lines in the field below and paste them as a string for the data variable in the example below:

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);
}
	

While being constructed, generator parses the product’s data. If the constructor didn’t throw exception, you are ready to generate serial numbers. Otherwise you will get exception with the description of the problem.

All the information serial number contains is defined using the generator’s properties. Some of them have constraints though. For example User Name and E-Mail fields cannot accept strings exceeding 255 bytes in UTF-8 encoding. In that case setting the property may lead to throwing exception.

After adjusting the generator, you need to call the Generate() method, that builds a serial number. It packs the data and encrypts the result. If the length of data exceeds the maximal size of serial number, exception will be thrown.

You may generate as many serial numbers as you need using the same generator. Each call to Generate() makes a new serial number with the same data. Although you may change generator’s properties if neccessary. To remove something from the serial number, just set the corresponding property to null.