[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3202
  • Last Modified:

PGP File Decryption using C# and Command Line Utility

I am using C# and PGP Command Line tool for decrypting symmetric encrypted pgp files.
As far as I know, I can decrypt files using this command:
pgp --decrypt --symmetric-passphrase 123 --output D:\lic_mmm.txt D:\lic.txt.pgp

That decrypts D:\lic.txt.pgp to D:\lic_mmm.txt with passphrase as 123.

This works fine when using cmd, now I want to automate this process in C#.

My code looks like the code below.

But this is not working, the command window appears and then hides showing a message: "Invalid argument"

What is wrong with the code?
System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.WorkingDirectory = @"D:\PGP Command Line";
                string args = @"--decrypt --symmetric-passphrase 123 --output D:\lic_mmm.txt D:\lic.txt.pgp";
                p.StartInfo.FileName = "pgp";
                p.StartInfo.Arguments = " " + args;
                p.Start();
                p.WaitForExit();

Open in new window

0
Mortaza Doulaty
Asked:
Mortaza Doulaty
  • 5
  • 2
2 Solutions
 
Mortaza DoulatyAuthor Commented:
Using this code (using cmd with /c option) solved my problem, but what was wrong with my code?

                args = @"/c pgp --decrypt --symmetric-passphrase ""123"" --output ""D:\lic_mmm.txt"" ""D:\Lic.txt.pgp""";
                p.StartInfo.FileName = "cmd";

Open in new window

0
 
Dave HoweCommented:
well, just a comment, but personally I wouldn't do it that way - instead of using command line PGP (and paying for the privilege of starting a clunky command shell per crypto op) use the bouncy castle c# libraries instead

http://www.bouncycastle.org/csharp/
0
 
Jaime OlivaresCommented:
I think you need to specify:
p.StartInfo.FileName = @"c:\fullpath\pgp";
0
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 
Mortaza DoulatyAuthor Commented:
>>p.StartInfo.FileName = @"c:\fullpath\pgp";

But I've specified .WorkingDirectory

Tried, no luck!




p.StartInfo.WorkingDirectory = @"D:\PGP Command Line";

Open in new window

0
 
Mortaza DoulatyAuthor Commented:
>>well, just a comment, but personally I wouldn't do it that way - instead of using command

I'll try this too.

I've tried GnuPG, it is working fine...
0
 
Dave HoweCommented:
gnupg is an option, and is at least free - but you are still having to start a command shell to run the command each time. a native library is much better :)
0
 
Mortaza DoulatyAuthor Commented:
>>but you are still having to start a command shell to run
Using a process (as in my previous code) solves the problem.

Tomorrow, I will check the native class you provided.
0
 
Mortaza DoulatyAuthor Commented:
Dear jaime_olivares,
  This worked for me:
    p.StartInfo.FileName = @"c:\fullpath\pgp.exe";

Dear DaveHowe,
  I tested Bouncy Castle tool and it worked fine, I'm gonna use this.

Thanks for your helps.
0

Featured Post

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now