//setup up database, make sure we can hit it or make the tables, 90% sure this will work private static bool scan_for_db() { MySQL_Interface MySQL = new MySQL_Interface(); //this is my layer over mysql connector List<string> databases = MySQL.mysql_select_database(my_username,my_password); bool found_keys = false;// looking for different tables bool found_data = false; foreach(string db in databases) { if (db == my_database) { //found database List<string> tables = MySQL.mysql_select_table(my_username,my_password,my_database); foreach (string table in tables) { if (table == "keys") { found_keys = true; }else{ if (table == "data") { found_data = true; } } } } } if (found_data && found_keys) // if both tables are there just return true { return true; } //Tables Need made Console.Write("Database was found? Can I make a 'keys' and 'data' table in " + my_database + "?[y/n] "); //asking is always nice if (Console.ReadKey().KeyChar == 'y') { //make tables if (!found_keys) { string command_text = "CREATE TABLE `" + my_database + "`.`" + my_db_table + "` ( "; command_text += @" `index` INT( 10 ) NOT NULL AUTO_INCREMENT , `modulus` VARCHAR( 256 ) NOT NULL , `exponent` INT( 6 ) NOT NULL , `active` TINYINT( 1 ) NOT NULL , `date_added` INT( 10 ) NOT NULL , `revoked` INT( 2 ) NOT NULL , PRIMARY KEY ( `index` ) ) ENGINE = INNODB DEFAULT CHARSET = latin1;"; MySQL.mysql_nonquery(my_username, my_password, my_database, command_text); command_text = @"SELECT COUNT(`index`) AS items FROM `" + my_db_table + "`"; List<List<string>> return_stuff = MySQL.mysql_query(my_username,my_password,my_database,command_text); if (return_stuff.Count > 0) { found_keys = true; } } if (!found_data) { string command_text = "CREATE TABLE `" + my_database + "`.`" + my_db_data + "` ( "; command_text += @"`index` INT NOT NULL AUTO_INCREMENT , `data` TEXT NOT NULL , `key_used` INT NOT NULL , PRIMARY KEY ( `index` ) ) ENGINE = MYISAM ;"; MySQL.mysql_nonquery(my_username, my_password, my_database, command_text); command_text = @"SELECT COUNT(`index`) AS items FROM `" + my_db_data + "`"; List<List<string>> return_stuff = MySQL.mysql_query(my_username,my_password,my_database,command_text); if (return_stuff.Count > 0) { found_data = true; } } if(found_keys && found_data) { //Foudn everything good to go return true; }else{ return false; } } return false; //this shouldnt be hit, compiler complained }
//show all the strings encrypted, for fun private static void option3_show_encrypted() { MySQL_Interface MySQL = new MySQL_Interface(); string command_text = @"SELECT * FROM `" + my_database + "`.`" + my_db_data + "`"; List<List<string>> return_stuff = MySQL.mysql_query(my_username,my_password,my_database,command_text); if (return_stuff.Count > 0) { Console.Write(Environment.NewLine + "||IND|| data || key used " + Environment.NewLine); for (int i = 0; i < return_stuff.Count; i++) { Console.Write("|| " + return_stuff[i][0] + " || " + return_stuff[i][1] + " || " + return_stuff[i][2] + Environment.NewLine); } } }
//show all the string unencrypted private static void option4_show_unencrypted() { MySQL_Interface MySQL = new MySQL_Interface(); string command_text = @"SELECT * FROM `" + my_database + "`.`" + my_db_data + "`"; List<List<string>> return_stuff = MySQL.mysql_query(my_username,my_password,my_database,command_text); if (return_stuff.Count > 0) { Console.Write(Environment.NewLine + "||IND|| data || key used " + Environment.NewLine); for (int i = 0; i < return_stuff.Count; i++) { Console.Write("|| " + return_stuff[i][0] + " || "); Console.Write(decrypt ((new System.IO.DirectoryInfo(System.Environment.CurrentDirectory)).ToString(), int.Parse(return_stuff[i][2]), return_stuff[i][1])); Console.Write (" || " + return_stuff[i][2] + Environment.NewLine); } } }
//show the key table for funzies private static void option2_get_key_table() { MySQL_Interface MySQL = new MySQL_Interface(); string command_text = @"SELECT * FROM `" + my_database + "`.`" + my_db_table + "`"; List<List<string>> return_stuff = MySQL.mysql_query(my_username,my_password,my_database,command_text); if (return_stuff.Count > 0) { Console.Write(Environment.NewLine + "||IND|| Modulus || Exponent || Active || Revoked ||" + Environment.NewLine); for (int i = 0; i < return_stuff.Count; i++) { Console.Write("|| " + return_stuff[i][0] + " || " + return_stuff[i][1].Substring(0, 34) + " || " + return_stuff[i][2] + " || " + return_stuff[i][3] + " || " + return_stuff[i][4] + " || " + Environment.NewLine); } } }