我对C#很新,因为我需要为我的老板制作一个简单的项目。
我想要收到的是:
就是这样。
我已经得到了什么:
我需要什么:
这是我目前的代码:
{
Process decrypt = new Process();
string processExecutable = @"C:\Windows\System32\cmd.exe";
if (!File.Exists(processExecutable))
throw new ApplicationException(string.Format("The executable file \"{0}\" does not exist.", processExecutable));
decrypt.StartInfo.FileName = processExecutable;
decrypt.StartInfo.Arguments = "/C openssl enc -d -aes-256-cbc -in FILES_IN.enc -out FILES_OUT.mp3 -pass file:./KEY_FILE.bin";
decrypt.StartInfo.UseShellExecute = false;
decrypt.StartInfo.RedirectStandardOutput = true;
decrypt.StartInfo.RedirectStandardError = true;
decrypt.StartInfo.RedirectStandardInput = true;
decrypt.StartInfo.CreateNoWindow = true;
decrypt.Start();
decrypt.BeginOutputReadLine();
decrypt.BeginErrorReadLine();
decrypt.WaitForExit();
decrypt.Close();
}
我应该如何修改它,以便能够在用户选择的文件上使用它?谢谢你的帮助。
答案 0 :(得分:0)
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog();
ofd.Multiselect = true;
DialogResult dr = ofd.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
foreach (String file in ofd.FileNames)
{
listView1.Items.Add(file);
getCommandlineResult(file, "path1", "path2");
}
}
}
public string getCommandlineResult(string userSelectedFilesToDecrypt, string UserSelectedFilesAlreadyDecrypted,
string user_selected_key_file)
{
string macAddress = string.Empty;
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = @"C:\Windows\System32\cmd.exe";
pProcess.StartInfo.Arguments = "openssl enc - d - aes - 256 - cbc -in " + userSelectedFilesToDecrypt + ".enc -out " +
UserSelectedFilesAlreadyDecrypted + ".mp3 - pass file:./ " +
user_selected_key_file + ".bin";
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true; //hide window
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
return strOutput;
}
你必须自己微调代码,因为我没有安装openssl,但这必须帮助你朝正确的方向发展。