Exemple #1
0
function send_timekoins($my_private_key, $my_public_key, $send_to_public_key, $amount, $message)
{
    $arr1 = str_split($send_to_public_key, 181);
    $encryptedData1 = tk_encrypt($my_private_key, $arr1[0]);
    $encryptedData64_1 = base64_encode($encryptedData1);
    $encryptedData2 = tk_encrypt($my_private_key, $arr1[1]);
    $encryptedData64_2 = base64_encode($encryptedData2);
    // Sanitization of message
    // Filter symbols that might lead to a transaction hack attack
    $symbols = array("|", "?", "=");
    // SQL + URL
    $message = str_replace($symbols, "", $message);
    // Trim any message to 64 characters max and filter any sql
    $message = filter_sql(substr($message, 0, 64));
    $transaction_data = "AMOUNT={$amount}---TIME=" . time() . "---HASH=" . hash('sha256', $encryptedData64_1 . $encryptedData64_2) . "---MSG={$message}";
    $encryptedData3 = tk_encrypt($my_private_key, $transaction_data);
    $encryptedData64_3 = base64_encode($encryptedData3);
    $triple_hash_check = hash('sha256', $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3);
    $sql = "INSERT INTO `my_transaction_queue` (`timestamp`,`public_key`,`crypt_data1`,`crypt_data2`,`crypt_data3`, `hash`, `attribute`) VALUES \n\t\t('" . time() . "', '{$my_public_key}', '{$encryptedData64_1}', '{$encryptedData64_2}' , '{$encryptedData64_3}', '{$triple_hash_check}' , 'T')";
    if (mysql_query($sql) == TRUE) {
        // Success code
        return TRUE;
    } else {
        return FALSE;
    }
}
Exemple #2
0
                 // Server public key is listed as a qualified generation server.
                 // Has the server submitted it's currency generation to the transaction queue?
                 $found_public_key_my_queue = mysql_result(mysql_query("SELECT * FROM `my_transaction_queue` WHERE `attribute` = 'G' LIMIT 1"), 0, "timestamp");
                 $found_public_key_trans_queue = mysql_result(mysql_query("SELECT * FROM `transaction_queue` WHERE `public_key` = '{$my_public_key}' AND `attribute` = 'G' LIMIT 1"), 0, "timestamp");
                 $join_peer_list = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `public_key` = '{$my_public_key}' LIMIT 1"), 0, "join_peer_list");
                 if (empty($found_public_key_my_queue) == TRUE && empty($found_public_key_trans_queue) == TRUE && time() - $join_peer_list >= 3600) {
                     // How much can be generated at one time?
                     $allowed_amount = peer_gen_amount($my_public_key);
                     //Not found, add it to transaction queue
                     $arr1 = str_split($my_public_key, 181);
                     $encryptedData1 = tk_encrypt($my_private_key, $arr1[0]);
                     $encryptedData64_1 = base64_encode($encryptedData1);
                     $encryptedData2 = tk_encrypt($my_private_key, $arr1[1]);
                     $encryptedData64_2 = base64_encode($encryptedData2);
                     $transaction_data = "AMOUNT={$allowed_amount}---TIME=" . time() . "---HASH=" . hash('sha256', $encryptedData64_1 . $encryptedData64_2);
                     $encryptedData3 = tk_encrypt($my_private_key, $transaction_data);
                     $encryptedData64_3 = base64_encode($encryptedData3);
                     $duplicate_hash_check = hash('sha256', $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3);
                     $sql = "INSERT INTO `my_transaction_queue` (`timestamp`,`public_key`,`crypt_data1`,`crypt_data2`,`crypt_data3`, `hash`, `attribute`)\n\t\t\t\t\tVALUES ('" . time() . "', '{$my_public_key}', '{$encryptedData64_1}', '{$encryptedData64_2}' , '{$encryptedData64_3}', '{$duplicate_hash_check}' , 'G')";
                     mysql_query($sql);
                 }
             }
             // Future generation allowed check
         }
         // Public Key Check
     }
     // Generation enabled check
 }
 // End Time allowed check
 //***********************************************************************************
 //***********************************************************************************
Exemple #3
0
function send_timekoins($my_private_key, $my_public_key, $send_to_public_key, $amount, $message)
{
    if (empty($my_private_key) == TRUE || empty($my_public_key) == TRUE || empty($send_to_public_key) == TRUE) {
        return FALSE;
    }
    ini_set('user_agent', 'Timekoin Client v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 3);
    // Timeout for request in seconds
    $arr1 = str_split($send_to_public_key, 181);
    $encryptedData1 = tk_encrypt($my_private_key, $arr1[0]);
    $encryptedData64_1 = base64_encode($encryptedData1);
    $encryptedData2 = tk_encrypt($my_private_key, $arr1[1]);
    $encryptedData64_2 = base64_encode($encryptedData2);
    // Sanitization of message
    // Filter symbols that might lead to a transaction hack attack
    $symbols = array("|", "?", "=");
    // SQL + URL
    $message = str_replace($symbols, "", $message);
    // Trim any message to 64 characters max and filter any sql
    $message = filter_sql(substr($message, 0, 64));
    $transaction_data = "AMOUNT={$amount}---TIME=" . time() . "---HASH=" . hash('sha256', $encryptedData64_1 . $encryptedData64_2) . "---MSG={$message}";
    $encryptedData3 = tk_encrypt($my_private_key, $transaction_data);
    $encryptedData64_3 = base64_encode($encryptedData3);
    $triple_hash_check = hash('sha256', $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3);
    $timestamp = transaction_cycle(0) + 1;
    $attribute = "T";
    $qhash = $timestamp . base64_encode($my_public_key) . $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3 . $triple_hash_check . $attribute;
    $qhash = hash('md5', $qhash);
    // Create map with request parameters
    $params = array('timestamp' => $timestamp, 'public_key' => base64_encode($my_public_key), 'crypt_data1' => $encryptedData64_1, 'crypt_data2' => $encryptedData64_2, 'crypt_data3' => $encryptedData64_3, 'hash' => $triple_hash_check, 'attribute' => $attribute, 'qhash' => $qhash);
    // Build Http query using params
    $query = http_build_query($params);
    // Create Http context details
    $contextData = array('method' => 'POST', 'header' => "Connection: close\r\n" . "Content-Length: " . strlen($query) . "\r\n", 'content' => $query);
    // Create context resource for our request
    $context = stream_context_create(array('http' => $contextData));
    // Try all Active Peer Servers
    $sql_result = mysql_query("SELECT * FROM `active_peer_list` ORDER BY RAND()");
    $sql_num_results = mysql_num_rows($sql_result);
    $return_results;
    for ($i = 0; $i < $sql_num_results; $i++) {
        $sql_row = mysql_fetch_array($sql_result);
        $ip_address = $sql_row["IP_Address"];
        $domain = $sql_row["domain"];
        $subfolder = $sql_row["subfolder"];
        $port_number = $sql_row["port_number"];
        $code = $sql_row["code"];
        $poll_peer = filter_sql(poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=send_tk&hash={$code}", $context));
        if ($poll_peer == "OK") {
            write_log("Peer: [{$ip_address}{$domain}:{$port_number}/{$subfolder}] Accepted the Transaction for Processing", "T");
            $return_results = TRUE;
        }
    }
    if ($return_results == TRUE) {
        // Success in sending transaction
        return TRUE;
    } else {
        // No peer servers accepted the transaction data :(
        write_log("No Peers Accepted the Transaction", "T");
        return FALSE;
    }
}
     $encrypt_data = $_POST["encrypt_me"];
     if (empty($encrypt_data) == TRUE) {
         $encrypt_data = "empty";
     }
     $key_create_micro_time = microtime(TRUE);
     require_once '../RSA.php';
     $rsa = new Crypt_RSA();
     extract($rsa->createKey($bits_level));
     $key_create_micro_time_done = microtime(TRUE);
     if (empty($privatekey) == FALSE && empty($publickey) == FALSE) {
         $symbols = array("\r");
         $new_publickey = str_replace($symbols, "", $publickey);
         $new_privatekey = str_replace($symbols, "", $privatekey);
         $encrypt_create_micro_time = microtime(TRUE);
         // Encrypt New Data
         $encrypt_data_new = tk_encrypt($new_privatekey, $encrypt_data);
         $encrypt_create_micro_time_done = microtime(TRUE);
         $decrypt_create_micro_time = microtime(TRUE);
         // Now Decrypt the same Data
         $decrypted_data = tk_decrypt($new_publickey, $encrypt_data_new);
         $decrypt_create_micro_time_done = microtime(TRUE);
         if (empty($decrypted_data) == TRUE) {
             $decrypted_data = '***DATA STRING TOO LONG FOR BITS ENTERED***';
         }
         $micro_time_variance = "Key Pair Creation [<strong>" . round(($key_create_micro_time_done - $key_create_micro_time) * 1000) . "</strong>] ms<br>\n\t\t\t\tData Encryption [<strong>" . round(($encrypt_create_micro_time_done - $encrypt_create_micro_time) * 1000) . "</strong>] ms<br>\n\t\t\t\tData Decryption [<strong>" . round(($decrypt_create_micro_time_done - $decrypt_create_micro_time) * 1000) . "</strong>] ms<br>\n\t\t\t\tTotal Time [<strong>" . round((microtime(TRUE) - $key_create_micro_time) * 1000) . "</strong>] ms";
         $text_bar .= " {$micro_time_variance} for <strong>{$bits_level}</strong> bit RSA Encryption";
     } else {
         // Key Pair Creation Error
         $text_bar = 'Key Creation Failed';
     }
 }