[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PGP File Decryption using C# and Command Line Utility

Posted on 2008-10-05
8
Medium Priority
?
3,171 Views
Last Modified: 2012-05-05
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
Comment
Question by:Mortaza Doulaty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 22643824
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
 
LVL 33

Accepted Solution

by:
Dave Howe earned 1000 total points
ID: 22644368
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
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1000 total points
ID: 22644446
I think you need to specify:
p.StartInfo.FileName = @"c:\fullpath\pgp";
0
Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 22645387
>>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
 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 22645391
>>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
 
LVL 33

Expert Comment

by:Dave Howe
ID: 22645449
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
 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 22645710
>>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
 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 22648990
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Provide an easy one stop to quickly get the relevant information on common asked question on Ransomware in Expert Exchange.
Worried about if Apple can protect your documents, photos, and everything else that gets stored in iCloud? Read on to find out what Apple really uses to make things secure.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question