void loadKeyFromFile(String path, String title, UserKey key) { int counter = 0; string line; long parsedValue; long[] data = new long[2]; System.IO.StreamReader file = new System.IO.StreamReader(@path); if (System.IO.File.ReadAllLines(path).Count() == 2) { while ((line = file.ReadLine()) != null) { if (long.TryParse(line, out parsedValue)) { data[counter] = Convert.ToInt64(line); } counter++; } file.Close(); if (title.Equals("private")) { key.setUpPrivateKey(data[0], data[1]); } else if (title.Equals("public")) { key.setUpPublicKey(data[0], data[1]); } } else { Controllers.showErrorBox("Error", "Wrong key file"); } }
public UserKey saveKeysToFile(String path, RSA rsa, UserKey key) { key = rsa.generateKeyParis(); if (path != null) { System.IO.File.WriteAllText(@path + "privateKey.txt", Convert.ToString(key.getPrivateKey()[0]) + "\n" + Convert.ToString(key.getPrivateKey()[1]) + "\n"); System.IO.File.WriteAllText(@path + "publicKey.txt", Convert.ToString(key.getPublicKey()[0]) + "\n" + Convert.ToString(key.getPublicKey()[1]) + "\n"); return(key); } else { return(key); } }
public void getKeyFilePath(System.Windows.Forms.OpenFileDialog openFileDialog, String title, UserKey key) { openFileDialog.FileName = ""; openFileDialog.Filter = "txt files (*.txt)|*.txt"; openFileDialog.FilterIndex = 2; openFileDialog.Title = "Load " + title + " key"; openFileDialog.RestoreDirectory = true; String path; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file path = openFileDialog.FileName; loadKeyFromFile(path, title, key); } else { if (title.Equals("private")) { // key = new UserKey(); } else if (title.Equals("public")) { // key = new UserKey(); } } }
public String getPathToSaveFile(System.Windows.Forms.SaveFileDialog saveFileDialog1, RSA rsa, UserKey key, String fileName, String filter) { saveFileDialog1.FileName = fileName; saveFileDialog1.Filter = filter; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { return(saveFileDialog1.FileName); } else { return(null); } }