Reputation: 161
I am encrypting a file using GnuPG in Visual Studio 2012 using C#.
When I decrypt this encrypted file it doesn't show row headers in the file. Below is what I have written for the encryption.
string gpgOptions = "--homedir "C:\GnuPG" --batch --yes --encrypt --armor --recipient [email protected] --default-key [email protected] --passphrase-fd 0 --no-verbose";
string inputText = "Name, Age
Dave, 19
Ryan, 21";
ProcessStartInfo pInfo = new ProcessStartInfo(gpgExecutable, gpgOptions);
pInfo.CreateNoWindow = true;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardInput = true;
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
_processObject = Process.Start(pInfo);
_processObject.StandardInput.Write(inputText);
I decrypt it using stdin with the below command:
gpg --output my.csv --decrypt A.gpg
my.csv is:
"Dave, 19
Ryan, 21";
I want it to be decrypted with the headers. What am I missing here?
Upvotes: 1
Views: 635
Reputation: 38732
You're telling gpg
to read the passphrase from stdin using --passphrase-fd 0
. Because of this, GnuPG will use everything up to the first newline as password.
This works anyway, as encryption does not require any passphrase. Try this (example is for unix systems, not Windows, but probably wouldn't look much different over there) to demonstrate the problem:
$ cat <<EOT | gpg -e --passphrase-fd 0 --recipient [email protected] | gpg -d
> foo
> bar
> EOT
Reading passphrase from file descriptor 0
You need a passphrase to unlock the secret key for
user: "Jens Erat <[email protected]>"
2048-bit RSA key, ID 3A5E68F7, created 2010-12-12 (main key ID D745722B)
gpg: encrypted with 2048-bit RSA key, ID 3A5E68F7, created 2010-12-12
"Jens Erat <[email protected]>"
bar
Solution: Remove --passphrase-fd 0
from the parameters.
Upvotes: 1