Need some help with pgp file decryption
anyone have an idea how to do it in c#?
I have it implemented through process.start ("cmd.exe", command)
but its not doing anything other than openning the C:\Windows\System32\IISExpress>
the command line not getting executed,
any help is appreciated.
Code Snippet:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "pgp --decrypt " + inputfile+ " -r \"inputphrase\" --passphrase \"passphrase\" --output " + outputfile+ ".txt";
process.StartInfo = startInfo;
process.Start();
Please suggest if there is way to achieve this.
The better way would be to use PGP (or OpenPGP, which is the same) library for C#/.NET.
There are free and opensource ones (like Bouncycastle), but they lack support, examples, etc.
Also there are better supported commercial libraries (like SecureBlackbox), but they cost some money.
Related
I am developing an application for managing Personal Hotspot of a Laptop
(Windows of Course).
I'm having a little difficulty in changing the Hotspot Name.
Here is my Code:
//For CMD Command
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = "CMD.exe";
startInfo.CreateNoWindow = true;
//Reading User Input in textBox1:
string name = textBox1.Text;
//CMD Argument:..., Which is currently written wrong to make it Easy to
//understand the problem
startInfo.Arguments = "/C netsh wlan set hostednetwork ssid="name";
process.StartInfo = startInfo;
process.Start();
Here, In the Arguments line, the syntax is wrong. The value assigned to Arguments should be a single string. I need to incorporate name, that has a dynamic value, with the rest of the string that is constant. How do I do that?
Unless I'm missing something here, seems to me that a simple string concatenation would do it:
startInfo.Arguments = "/C netsh wlan set hostednetwork ssid=" + name;
There are several ways you can create a dynamic string:
For your specific case, Concatenation is the best choice as your string is very simple.The reason you would choose this method for your case is because it is very light as compared to other methods and has a clean enough syntax.
startInfo.Arguments = "/C netsh wlan set hostednetwork ssid=" + name;
For anything more complicated, string.Format is a popular go to. You would generally use it to combine more complex strings than your example. This tutorial covers the subject thoroughly.
startInfo.Arguments = string.Format("/C netsh wlan set hostednetwork ssid={0}", name);
The release of C#6.0 included a neat feature: interpolated strings. It is for the most part just syntactic sugar for string.Format, where the line below is turned into the line above at compile time. There are subtle differences, but those are not important in this thread.
startInfo.Arguments = $"/C netsh wlan set hostednetwork ssid={name}";
And lastly, if you need to change a string more than a few times (I usually use the rule of 5 - i.e. a string changes more than 5 times), I would use the StringBuilder class. A great application, among many others, would be a long loop that modifies a certain string each iteration. See This Tutorial.
In this case, the Garbage Collector will thank you for a using a StringBuilder!
i am performing offline operations on images taking image as a input with parameters and processing it in VTK C++ exe i am unable to pass parameters to C++ exe through C# program and retrive output .
please explain me with some example
If you just mean that you have a compiled C++ program (which we'll call "foo.exe", with path stored in string "exe_folder") and you want to call that with command line parameters (stored in string "exe_params") from C#, then the following should work:
string exe_params = "target_image.jpeg HOUGH_TRANSFORM"; // Or whatever params are appropriate.
string exe_full_path = Path.Combine(exe_folder, "foo.exe");
Process proc = System.Diagnostics.Process.Start(exe_full_path, exe_params);
https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx
Let say that your executable is called test.exe and it is in the test dir. For me, the following would be working:
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C cd C:\\..test\\ && test.exe target_image.jpg yourtransformation";
process.StartInfo = startInfo;
process.Start();
If you have further problems, try setting the working directory of processStartInfo.
If I run the following command in a command prompt, it works:
"C:\Program Files (x86)\AppFolder\do.exe"
If I try to run the same thing as a process:
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = #"/c ""C:\Program Files (x86)\AppFolder\do.exe""";
using (Process process = Process.Start(startInfo))
{
...
}
It does not appear to run. If I look at the startInfo.Arguments, it appears as follows:
/c \"C:\\Program Files (x86)\\AppFolder\\do.exe\"
What am I missing? Can you not pass arguments that have quotes or spaces? I see a lot of examples where people are passing items with spaces/quotes in just fine, but following them just doesn't seem to work. This is the narrowest example I can think of.
EDIT: If I just create a shortcut so I don't use spaces or quotes, it works:
startInfo.Arguments = #"/c D:\_test\Do.lnk";
I do not use '#'. This is correct implementation:
startInfo.Arguments = "/c \"C:\\Program Files (x86)\\AppFolder\\do.exe\"";
im trying to execute remote process using psexec in c# application.
this is my code :
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C psexec \\\\"+hostname +" "+command;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
response = process.StandardOutput.ReadToEnd();
process.WaitForExit();
the problem is im not getting response only if command="", i get the definition of the psexec command in response but if command="dir" for exemple i get nothing in response . any help.
You forgot to read standard error as well. Maybe, psexec writes to that.
I suggest you use one of the top voted snippets of stack overflow, to be found by: site:stackoverflow.com process RedirectStandardOutput. There are hundreds of such questions. Most solutions are subtly wrong but certainly better than this one which is clearly incorrect.
This is a good checklist.
I have researched and attempted to do this myself, but with no luck. I am trying to execute a java app and pass it a few variables. It is finding the java and running it, but not passing it any variables, here is what I have so far -
Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = #"-jar javaapp.jar" + "host:port" + "password" + "/say" + "test";
startInfo.FileName = "java";
proc.StartInfo = startInfo;
proc.Start();
I cant work this out at all. I dont want to use any third party software (unless it can be packaged in the .EXE) as this is meant to be distributed to people who need it. Any help is thanked.
You need to put spaces in the strings you're concatenating, your command currently looks like
java -jar javaapp.jarhost:portpassword/saytest
The simplest way is to use string.Format:
string command1 = "/say"
string command2 = "test"
string args = string.Format("-jar javaapp.jar {0}:{1} {2} {3} {4}", host, port, password, command1, command2);
startInfo.Arguments = args;
Arguments is a string - the way you have it they'll all be mashed together with no space separating them.
The # symbol in C# is used for literal format of string; it looks like you're trying to use it to build an array or something.