Description
The UNIX version of the key generator is a PHP file that contains all the necessary information for serial number generation. The file is located in %Examples%\Keygen\PHP. Below, we describe the key points of using such a generator.
Configuring the generator
At the beginning of the PHP file, the setup code is located:
//////////////////////////////////////////////////////////////////////////////////////////////
// The following lines are generated by VMProtect License Manager
$exported_algorithm = "RSA";
$exported_bits = 2048;
$exported_private = "PJvj4kEpoQMIpYK+9wEt......xKeiSZgzdiln8Q==";
$exported_modulus = "rOlny/3QgZb/VmGr3CmY......I6ESAUmtQ+RBqQ==";
$exported_product_code = "oLQdGUn8kVk=";
//////////////////////////////////////////////////////////////////////////////////////////////
This code is automatically generated by VMProtect (see Exporting product parameters) and is unique for each product. It is crucial to copy it accurately; otherwise, the generator will not work correctly.
Contents of a key
The generator then specifies the contents of a serial number. The contents are defined in an array, with all possible parameters listed below. However, in real applications, some of them may be omitted:
$params = array(
user_name => "John Doe", // UTF-8!
email => "john@doe.com",
hwid => "vHGMdMRvGCPjWcCQ", // Exactly as returned by VMProtectGetCurrentHWID
expire_date => array(year => 2009, month => 10, day => 1),
maxbuild_date => array(year => 2009, month => 10, day => 1),
time_limit => 10,
user_data => base64_decode("CGCvRvMWcPHGdMjQ"), // string of bytes
);
Successful key generation handler function
Below is a simple function called upon successful generation of a serial number. The only parameter passed to it is the serial number string. The function must pass the serial number to the caller (an e-commerce agent), usually using the echo command. The string is optionally split into 75-character lines for convenience. This function can also send the generated serial number by e-mail to the developer or store it in a database.
function OnSerialGenerated($serial)
{
$serial = wordwrap($serial, 75, "\n", true);
echo $serial;
}
Key generator error handler function
The final part of the code that requires attention is the function called when something goes wrong. This function receives a string containing the error message, and after it finishes, the die() function is called. The handler must do two things: return a message to the e-commerce agent indicating that the key will be sent manually, and send detailed error information to the developer for troubleshooting and manual key generation.
function OnSerialGenerationFailed($details)
{
echo "You will receive the serial number within the next 24 hours"; // message to the customer
// mail("support@vendor.com", "Houston, we have a problem", $details); // message to vendor
}
There are several possible causes of errors: incorrect algorithm parameters, invalid key parameters, a user name or e-mail that is too long, or a serial number that exceeds the bit length specified by the algorithm. That is why the OnSerialGenerationFailed function must send detailed information about the issue to the developer so that a serial number can be generated and sent to the customer manually.
Other things to consider
The examples provide a simplified version of the key generator. They do not take into account recommendations for developing web generators. They do not check the caller’s IP address and do not validate input parameters. Please take this into account when developing your own generator based on this example.
A user name and e-mail must be passed as UTF-8 strings. Ensure that your e-commerce agent sends this data in UTF-8 encoding, or convert it if necessary. Incorrect encoding will not result in an invalid serial number, but the displayed registration name may differ from the actual user’s name, which may surprise the user in the “About” window of the application.
Asymmetric encryption is a computationally complex process. If implemented in pure PHP without third-party libraries, serial number generation can take tens of seconds. The generator uses gmp_powm, bi_powmod, and bcpowmod functions whenever available. If serial number generation is too slow on your hosting, we recommend asking your hosting provider to enable these functions. For example, the gmp_powm function is significantly faster than bcpowmod.