Ok, I have a text file containing an encrypted string of text called textToDecrypt.txt
. I run the following command in OpenSSL to create a file called decrypted.txt
containing the decrypted data:
rsautl -decrypt -inkey private.pem -in textToDecrypt.txt -out decrypted.txt
When I type this in, the next thing it asks me for is my Passphrase which is fine when I am doing this manually, however I am planning to do this programatically in C# and it is causing issues when I send the first command to the program followed by the second command containing the passphrase, as shown below.
My question is, can I include the passphrase as part of the initial command, instead of sending the decrypt command first followed by the passphrase?
Just to clarify, when I do this manually (by opening up cmd.exe, navigating to the directory containing my openssl.exe and running this then typing in the first command followed by the passphrase when prompted) everything works perfectly, when I try to recreate this process programmatically things go wrong.
I tried to use Thread.Sleep() to wait a few seconds before sending the second command but it had the same result.
Edit: My C# code is below:
Process openSsl = new Process();
openSsl.StartInfo.FileName = processExecutable;
openSsl.StartInfo.UseShellExecute = false;
openSsl.StartInfo.CreateNoWindow = false;
openSsl.StartInfo.RedirectStandardInput = true;
openSsl.Start();
openSsl.StandardInput.WriteLine("rsautl -decrypt -inkey private.pem -in textToDecrypt.txt -out decrypted.txt");
openSsl.StandardInput.WriteLine("MyPassphrase");
openSsl.StandardInput.Close();