Video Screencast Help

PGP Command Line File Encryption

Created: 14 Aug 2014 • Updated: 26 Aug 2014

Hi Experts,

I am new to the PGP command line tool & we are using PGP command line tool for encrypting the files and we are facing some issue.

We got public keys from our partners. now we have to encrypt text file using these public keys.

what steps I need to follow to encrypt the file?

I am using --encrypt "{0}" --recipient "{1}" --output "{2}" command to encrypt the file.

Q1 : Do I need to import the public keys I got from our partners? If yes How to do that?

Q2: Can we keep multiple keys in same folder where PGP.exe exists?

Q3: How to pass public key in above encrypt command?

Below is the code we are using for encryption -

 private static void PGPEncrypt(string inputFile, string outputFile)

                ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(ConfigurationManager.AppSettings[Constants.PGP_Install_Path], ConfigurationManager.AppSettings[Constants.PGP_Execute_FileName]));
                startInfo.Arguments = string.Format(ConfigurationManager.AppSettings[Constants.PGP_Encrypt_Command], inputFile, ConfigurationManager.AppSettings[Constants.PGP_Recipient], outputFile);
                startInfo.RedirectStandardError = true;
                startInfo.RedirectStandardOutput = true;
                startInfo.UseShellExecute = false;
                startInfo.CreateNoWindow = true;
                Process pgpProcess = Process.Start(startInfo);

                string output = pgpProcess.StandardOutput.ReadToEnd();
                string error = pgpProcess.StandardError.ReadToEnd();
                if (!File.Exists(outputFile))
                    throw new Exception(string.Format("Encryption failed,no encrypted file{0} ,Error :{1} ", outputFile, error));

            catch (InvalidOperationException oEx)
            catch (Win32Exception wEx)
            catch (Exception ex)


Any help will be appreciated.



Operating Systems: