public string decryptString(string toDecrypt) { GpgInterface.ExePath = ExePath; string path = Directory.GetCurrentDirectory() + "\\" + GetUniqueKey() + ".txt"; string pathout = path + ".out"; System.IO.File.WriteAllText(path, toDecrypt); GpgDecrypt Decrypt = new GpgDecrypt(path, pathout); Decrypt.AskPassphrase = GetPassword; GpgInterfaceResult result = Decrypt.Execute(); System.IO.File.Delete(path); if (result.Status == GpgInterfaceStatus.Success) { string toReturn = System.IO.File.ReadAllText(pathout); System.IO.File.Delete(pathout); return toReturn; } else { throw new Exception("Decryption Failed"); } }
private void passFiles_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { FileInfo selectedFile; if (e.NewValue is System.IO.FileInfo) { selectedFile = (FileInfo)e.NewValue; } else { return; } string tmpDecryptionFileName = selectedFile.FullName + ".tmp"; GpgDecrypt decrypt = new GpgDecrypt(selectedFile.FullName, tmpDecryptionFileName); GpgInterfaceResult result = decrypt.Execute(); if (result.Status == GpgInterfaceStatus.Success) { displayText.Text = System.IO.File.ReadAllText(tmpDecryptionFileName); File.Delete(tmpDecryptionFileName); } }
/// <summary> /// Decrypt the file into a tempfile /// </summary> /// <param name="path"></param> /// <param name="clear"></param> private void DecryptPass(string path, bool clear = true) { var f = new FileInfo(path); if (f.Exists && f.Length > 0) { this.tmpfile = Path.GetTempFileName(); var decrypt = new GpgDecrypt(path, this.tmpfile); { // The current thread is blocked until the decryption is finished. var result = decrypt.Execute(); this.DecryptCallback(result, clear); } } else { txtPassDetail.Text = Strings.FrmMain_DecryptPass_Empty_file; } }
// // Decrypt functions // // Decrypt the file into a tempfile. private void decrypt_pass(string path, bool clear = true) { FileInfo f = new FileInfo(path); if (f.Length > 0) { tmpfile = Path.GetTempFileName(); GpgDecrypt decrypt = new GpgDecrypt(path, tmpfile); { // The current thread is blocked until the decryption is finished. GpgInterfaceResult result = decrypt.Execute(); Decrypt_Callback(result, clear); } } }
/// <summary> /// Fires a decrypt thread with a callback the encrypts it again, used to make the keys current /// </summary> /// <param name="path"></param> private void Recrypt(string path) { string tmpFile = Path.GetTempFileName(); GpgDecrypt decrypt = new GpgDecrypt(path, tmpFile); { // The current thread is blocked until the decryption is finished. GpgInterfaceResult result = decrypt.Execute(); this.DecryptCallback(result, tmpFile, path); } }