if ($calcMacEachChunk) {
        $file_mac = str_to_a32($mac_str);
        mcrypt_generic_deinit($m_td1);
        mcrypt_module_close($m_td1);
        mcrypt_generic_deinit($m_td2);
        mcrypt_module_close($m_td2);
    } else {
        $file_mac = FileMac($lfile, $fsize, a32_to_str(array_slice($ul_key, 0, 4)), a32_to_str(array($ul_key[4], $ul_key[5], $ul_key[4], $ul_key[5])));
    }
    $body = substr($upfiles, strpos($upfiles, "\r\n\r\n") + 4);
    if (is_numeric($body)) {
        check_errors($body, 'Upload Error');
    }
    $meta_mac = array($file_mac[0] ^ $file_mac[1], $file_mac[2] ^ $file_mac[3]);
    $attributes = array('n' => basename($lname));
    $enc_attributes = enc_attr($attributes, array_slice($ul_key, 0, 4));
    $key = array($ul_key[0] ^ $ul_key[4], $ul_key[1] ^ $ul_key[5], $ul_key[2] ^ $meta_mac[0], $ul_key[3] ^ $meta_mac[1], $ul_key[4], $ul_key[5], $meta_mac[0], $meta_mac[1]);
    $file = apiReq(array('a' => 'p', 't' => $T8['root_id'], 'n' => array(array('h' => $body, 't' => 0, 'a' => base64url_encode($enc_attributes), 'k' => a32_to_base64(encrypt_key($key, $T8['master_key']))))));
    if (is_numeric($file[0])) {
        check_errors($file[0], 'Save file error');
    }
    $public_handle = apiReq(array('a' => 'l', 'n' => $file[0]['f'][0]['h']));
    if (is_numeric($public_handle[0])) {
        check_errors($public_handle[0], 'Error getting public fileid');
    }
    $key = substr($file[0]['f'][0]['k'], strpos($file[0]['f'][0]['k'], ':'));
    $decrypted_key = a32_to_base64(decrypt_key(base64_to_a32($key), $T8['master_key']));
    $download_link = "https://mega.co.nz/#!{$public_handle[0]}!{$decrypted_key}";
}
// secure_rand() function from: http://www.zimuel.it/en/strong-cryptography-in-php/
function secure_rand($length)
Esempio n. 2
0
function uploadfile($filename)
{
    global $master_key, $root_id;
    $data = file_get_contents($filename);
    $size = strlen($data);
    $ul_url = api_req(array('a' => 'u', 's' => $size));
    $ul_url = $ul_url->p;
    $ul_key = array(0, 1, 2, 3, 4, 5);
    for ($i = 0; $i < 6; $i++) {
        $ul_key[$i] = rand(0, 4294967295.0);
    }
    $data_crypted = aes_ctr_encrypt($data, a32_to_str(array_slice($ul_key, 0, 4)), a32_to_str(array($ul_key[4], $ul_key[5], 0, 0)));
    $completion_handle = post($ul_url, $data_crypted);
    $data_mac = cbc_mac($data, array_slice($ul_key, 0, 4), array_slice($ul_key, 4, 2));
    $meta_mac = array($data_mac[0] ^ $data_mac[1], $data_mac[2] ^ $data_mac[3]);
    $attributes = array('n' => basename($filename));
    $enc_attributes = enc_attr($attributes, array_slice($ul_key, 0, 4));
    $key = array($ul_key[0] ^ $ul_key[4], $ul_key[1] ^ $ul_key[5], $ul_key[2] ^ $meta_mac[0], $ul_key[3] ^ $meta_mac[1], $ul_key[4], $ul_key[5], $meta_mac[0], $meta_mac[1]);
    return api_req(array('a' => 'p', 't' => $root_id, 'n' => array(array('h' => $completion_handle, 't' => 0, 'a' => base64urlencode($enc_attributes), 'k' => a32_to_base64(encrypt_key($key, $master_key))))));
}
Esempio n. 3
0
function enc_options($values)
{
    extract($values);
    # extract $options and $selection
    if (!is_array($selection)) {
        $selection = array($selection);
    }
    foreach ($options as $option) {
        if (in_array($option[0], $selection)) {
            $selected = ' selected';
        } else {
            $selected = '';
        }
        if ($option[0] !== $option[1]) {
            $value = ' value="' . enc_attr($option[0]) . '"';
        } else {
            $value = '';
        }
        $display = enc_htmlnbsp($option[1]);
        $out .= "<option{$value}{$selected}>{$display}</option>\n";
    }
    return $out;
}