public SecretThing DecryptSecret(SecretThing encryptedSecret, String key) { SecretThing tempForDecryptedVals = new SecretThing(); tempForDecryptedVals.title = AESDecryption(encryptedSecret.title, key, true); tempForDecryptedVals.url = AESDecryption(encryptedSecret.url, key, true); tempForDecryptedVals.comment = AESDecryption(encryptedSecret.comment, key, true); tempForDecryptedVals.password = AESDecryption(encryptedSecret.password, key, true); tempForDecryptedVals.privateKey = AESDecryption(encryptedSecret.privateKey, key, true); tempForDecryptedVals.secretId = encryptedSecret.secretId; return(tempForDecryptedVals); }
public SecretThing ConvertStringToSecret(String inputString) { SecretThing recordSecret = new SecretThing(); String[] words = inputString.Split(new string[] { "||o||" }, StringSplitOptions.None); recordSecret.title = words[0]; recordSecret.url = words[1]; recordSecret.comment = words[2]; recordSecret.password = words[3]; recordSecret.privateKey = words[4]; return(recordSecret); }
public SecretThing ReadSingleResult(int secretID, String convertedPwd, String databaseFilePath) { String sql = "select * from secrets where secretId = " + secretID; SecretThing clearTxtSecret = new SecretThing(); SQLiteCommand command = new SQLiteCommand(sql, sql_con); SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); // this breaks silently if there's more than 1. // it may break noisily if there's no result! clearTxtSecret = ConvertReaderItemToSecret(reader, convertedPwd); return(clearTxtSecret); }
private SecretThing ConvertReaderItemToSecret(SQLiteDataReader reader, String convertedPwd) { SecretThing encryptedtSecret = new SecretThing(); encryptedtSecret.title = reader["title"].ToString(); Console.WriteLine("title: {0}", encryptedtSecret.title); encryptedtSecret.comment = reader["comment"].ToString(); encryptedtSecret.url = reader["url"].ToString(); encryptedtSecret.password = reader["password"].ToString(); // This seems like going round the houses but... String realtmp = reader["secretId"].ToString(); Console.WriteLine("secretIdL {0}", realtmp); encryptedtSecret.secretId = Int32.Parse(realtmp); encryptedtSecret.privateKey = reader["privateKey"].ToString(); SecretThing clearTextSecret = crypt.DecryptSecret(encryptedtSecret, convertedPwd); return(clearTextSecret); }
// may need to change the return type to be a list containing the updated // contents of the table. public void WriteSingleResult(SecretThing inputSecret, String convertedPwd, String databaseFilePath) { int countId = GetCount(databaseFilePath); inputSecret.secretId = countId + 1; Console.WriteLine("inputSecret.secretId: {0}", inputSecret.secretId); SecretThing encyptedSecret = crypt.EncryptSecret(inputSecret, convertedPwd); String concat = "\"" + encyptedSecret.secretId + "\"," + "\"" + encyptedSecret.title + "\"," + "\"" + encyptedSecret.comment + "\"," + "\"" + encyptedSecret.url + "\"," + "\"" + encyptedSecret.password + "\"," + "\"" + encyptedSecret.privateKey + "\""; Console.WriteLine("concat: {0}", concat); String sql = "insert into secrets (secretId, title, comment, url, password, privateKey) values (" + concat + ")"; Console.WriteLine("sql string = {0}", sql); ExecuteQuery(sql, databaseFilePath); }
private void saveButton_Click(object sender, EventArgs e) { Console.WriteLine("Oi!! Title: {0}", titleTextBox.Text); if (string.IsNullOrWhiteSpace(titleTextBox.Text)) { MessageBox.Show("Title is mandatory!"); } else { SecretThing newSecret = new SecretThing(); newSecret.title = titleTextBox.Text; newSecret.url = urlTextBox.Text; newSecret.comment = commentTextBox.Text; newSecret.password = passwordTextBox.Text; newSecret.privateKey = keyTextBox.Text; newSecret.secretId = 1; dbActions.WriteSingleResult(newSecret, _convertedPwd, constants.databaseFile); //String _oneLiner = ConvertInputToString(); } }
public void DeleteSingleResult(SecretThing inputSecret, String databaseFilePath) { // to do. same thing: probably need to return this as a list. }
{// url comment password key public String ConvertSecretToString(SecretThing inputSecret) { String resultString = inputSecret.title + "||o||" + inputSecret.url + "||o||" + inputSecret.comment + "||o||" + inputSecret.password + "||o||" + inputSecret.privateKey; return(resultString); }