function encrypt_get_vars($var)
{
    assert(isset($var));
    global $_CONFIG;
    global $_RUN;
    // Generate checksum if not already done so..
    if ($_RUN['current_page_checksum'] == NULL) {
        $_RUN['current_page_checksum'] = generate_checksum();
    }
    // Things get real messy when they are not strings (like ints)
    $var = (string) $var;
    // Mix string with checksum and random chars...
    $var = substr($_RUN['current_page_checksum'], 0, 5) . $var . substr($_RUN['current_page_checksum'], 5, 5);
    for ($s = "", $i = 0; $i != strlen($var); $i++) {
        $s .= chr(rand(0, 255)) . $var[$i];
    }
    // Encrypt the string
    mcrypt_generic_init($_CONFIG['MCRYPT_TD'], $_CONFIG['MCRYPT_KEY'], $_CONFIG['MCRYPT_IV']);
    $s = mcrypt_generic($_CONFIG['MCRYPT_TD'], $s);
    // Encode it Bas64 (YUK!)
    for ($i = 0; $i != 1; $i++) {
        $s = base64_encode($s);
    }
    // And return it in a html-friendly way
    return rawurlencode($s);
}
Beispiel #2
0
function DecodeRegistrationKey($serial_number, $registration_key)
{
    if (strlen($serial_number) == 0 || strlen($registration_key) == 0) {
        return false;
    }
    $key = $registration_key;
    $key = str_replace('-', '', $key);
    $key = str_replace(' ', '', $key);
    $key = strtoupper($key);
    // get the checksum from the key.  It will be the last char of the key
    $checksumFromKey = ord($key[strlen($key) - 1]) - ASCII_BIG_A;
    $key = substr($key, 0, strlen($key) - 1);
    // store off this key so we can compare checksum later
    $keyToCompareChecksumTo = $key;
    list($key, $version) = ExtractFromByteArray($key, false);
    list($key, $product) = ExtractFromByteArray($key, false);
    if ($version == -1 || $product == -1) {
        return false;
    }
    // decode the rest of the key
    $arr = DecodeHolodeckBasicKey($key);
    if (!$arr) {
        return false;
    }
    $data = $arr[0];
    $key = $arr[1];
    $data->productType = $product;
    $data->keyVersion = $version;
    $data->serialNumber = $serial_number;
    $data->registrationKey = $registration_key;
    //make sure that what is left of the key matches the serial number encoding
    $computedSerialNumber = GenerateSerialNumberByteArray($data->serialNumber);
    if ($computedSerialNumber != $key) {
        return false;
    }
    // check the original checksum with the computed checksum to make sure it is valid
    $computedChecksum = generate_checksum($keyToCompareChecksumTo);
    if ($computedChecksum != $checksumFromKey) {
        return false;
    }
    return $data;
}