# UNIX-version

### Description

The UNIX-version of the key generator is a PHP file that contains all necessary information for serial number generation. The file is located in Keygen\PHP. Below we describe the key points of using such a generator.

### Configuring the generator

In the beginning of the PHP file, the setup code is located:

    //////////////////////////////////////////////////////////////////////////////////////////////
    // The following lines should be 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 particular product. It is crucial to copy it accurately, as otherwise the generator will work incorrectly.

### Contents of a key

Then, the generator specifies the contents of a serial number The contents are specified in an array, with all possible parameters of the key 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 you can see a simplest function called upon successful generation of a serial number. The only parameter sent to it is a serial number string. The function must pass the serial number to the caller (an e-commerce agent), usually with the echo command. The string is preliminarily split to sub-strings 75 symbols each, for convenience. Also, this function could send the generated serial number by e-mail to the developer or add it to 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 needs our attention is a function called when something goes wrong. This function receives a string with the error message, and when it finishes, the die() function is called. The handler function must do two things: instead of a key, return to an e-commerce agent a message saying the key will be sent manually. And send to the developer an exhaustive information about the error to fix it and generate the key manually.

    function OnSerialGenerationFailed($details)
    {
            echo "You will receive serial number in 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 mistakes: incorrect parameters of the algorithms, incorrect parameters of the key, a too long user name or e-mail, or a too long serial number that doesn't fit to the number of bits specified in the algorithm. That is why the OnSerialGenerationFailed function must send a detailed information about the issue to the developer, so he could generate a serial number and send it to the customer.

### Other things to consider

Examples hold a simplified version of the key generator. It doesn't take into account recommendations to develop web generators. It does not check the IP address of the caller and does not analyze input parameters. Please pay attention to this when developing your own generator based on this one.

A user name and an e-mail must be passed as UTF-8 strings. Make sure your e-commerce agent sends these data in the UTF-8 encoding, or transcode the information if this is not so. Wrong encoding won't lead to an incorrect serial number generated, but the registration name displayed for such a serial number can be different from the real user's name, so he or she may be surprised to see it in the "About" window of the application

Asymmetric encryption is a complex mathematical process. If it is implemented using pure PHP without any third-party libraries, serial number generation can take dozens of seconds. The generator uses gmp_powm, bi_powmod, bcpowod functions whenever they are available. If serial number generation take too long on your hosting, we recommend to ask the hosting provider to enable these functions. For example, the gmp_powm function works ten of times faster than bcpowmod.

© 2006-2015 Copyright VMProtect Software