EldoS | Feel safer!

Software components for data protection, secure storage and transfer

PGP Decrypting Multiple Files

Posted: 08/07/2008 10:05:14
by Robert Swider (Standard support level)
Joined: 08/07/2008
Posts: 1

I'm using the PGP component to decrypt a series of files in a single directory. When I loop over the files and pass them to my decryption component, the first file is decrypted just fine. After the first file, I receive an exception: "No appropriate OpenPGP secret key for decryption found". I'm certain all files are encrypted with the same key, and if I delete the first file and start with one that previous failed, it works on that one, but fails on the next.

I've even tried recreating my pgpreader for each iteration, and just reusing the keyring, but that doesn't work either. The common thread is whenever I try to reuse the keyring, it fails after the first use.

I've already got a workaround; I use keyring.exportto(tmpKeyring), so I'm essentially creating a new keyring with a copy of all my original keys, but that seems like a lot of hoops for something that strikes me as fairly common. When I tried to reuse the keyring for encrypting, it works fine on numerous files, which makes this all the more odd.

Here is a snippet of my code. Assume I'm creating and filling my keyring 'above' this. As I said, I know it's a valid keyring instance.
This is the version that fails:

string srcDirectory = @"c:\temp";
string srcFilemask = "*.pgp";

         foreach (string encFile in Directory.GetFiles(srcDirectory, srcFilemask))
            //Output filename is just the encrypted filename with '.txt' appended.
            String outputFile = encFile + ".txt";

               using (SBPGP.TElPGPReader pgpReader = new SBPGP.TElPGPReader())
                  //Assign the private keyring to the decrypting keys.
                  pgpReader.DecryptingKeys = secKeys;

                  //Set the name of the output file.
                  pgpReader.OutputFile = outputFile;

                  //Attempt to decrypt the file.
            catch (Exception ex)


Anyone have an idea if I'm doing something horribly wrong, or if I should be able to decrypt multiple files?


Posted: 08/07/2008 10:15:29
by Eugene Mayevski (Team)

Yes, you should be able to decrypt several files in a row. Most likely some internal variable is not reset properly in the components. Try modifying some sample application to reproduce the issue, and post this modified sample to the helpdesk, we will check it.

Sincerely yours
Eugene Mayevski
Posted: 08/07/2008 10:22:29
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 442

Also, please check if the Passphrase property of your secret key is set to a valid value each time or assign OnKeyPassphrase() event handler.



Topic viewed 1369 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!