PGPLib::DecryptFile throw exception for "optional" output file name

26 views
Skip to first unread message

Matt Hull

unread,
Jul 6, 2018, 1:17:51 PM7/6/18
to DidiSoft Forum
The XML Documentation for the last parameter (outputFileName) of the PGPLib::DecryptFile method states:

File name of the Output decrypted file (absolute or relative path). Optional parameter. If empty the name stored in the PGP decrypted file is used.

Passing null or the empty string for the last parameter throws an exception. This is true for all of the overloads of this method (those that take FileInfo instead of strings or use KeyStore/KeyPairs, etc).

Looking at the source code, there is no check for an empty parameter.  The code automatically tries to open a file stream to the path provided:
 using (Stream fOut = File.Create(outputFileName))

When null/empty the framework throws the appropriate exception.

Either the XML documentation needs to be updated to indicate that the parameter is NOT optional, or these methods should be updated to work as the XML documentation indicates. I know that the functionality is available (I'm pretty sure that the Extract PGP archive related methods do exactly this). Other PGP applications are able to determine the name of the files, so it must be encoded somehow.

Thanks,

Matt

DidiSoft Support

unread,
Jul 6, 2018, 2:06:17 PM7/6/18
to didisof...@googlegroups.com, Matt Hull

Hi Matt,

Thank you for this notice.

In earlier versions this was supported but due to the library being used mostly in ASP.NET applications, decryption of a file this way ended being in a folder not expected by the developers.

This has been removed from the documentation. You can download the updated setup, if you use Helpviewer format.

Kind Regards
Peter Kalef
Technical Support
DidiSoft Inc | Phone: +1-256-907-7816 | Fax: +1-256-907-7816 | Web: www.didisoft.com
--
You received this message because you are subscribed to the Google Groups "DidiSoft Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to didisoft_foru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Hull

unread,
Jul 6, 2018, 2:23:01 PM7/6/18
to DidiSoft Support, didisof...@googlegroups.com
Is it possible to determine the name of the file? In otherwords, are there any methods that I can invoke to get the original file name? Or do I perhaps need to use the DecryptToFolder methods? I don't know if those will work if its a single encrypted file though.

To unsubscribe from this group and stop receiving emails from it, send an email to didisoft_forum+unsubscribe@googlegroups.com.

DidiSoft Support

unread,
Jul 6, 2018, 2:37:34 PM7/6/18
to Matt Hull, didisof...@googlegroups.com

Hi Matt,

Yes, of course.

In the cases when you don't know in advance the contents of an incoming encrypted file or you would like to implement complex logic depending on the encrypted content (for example for images one output location, for documents another, etc.) you have to use the methods of another helper class DidiSoft.Pgp.Inpsect.PGPInspectLib.

Here is a simple example from:
https://www.didisoft.com/net-openpgp/examples/analyzing-unknown-openpgp-archives/

that illustrates how to list what's inside a .pgp file:


using DidiSoft.Pgp.Inspect;
 
public class InspectEncryptedFile
{
 public void Demo()
 {
  //
  // Inspect the content of an encrypted file without decrypting it
  //            
  String privateKey = @"c:\private_key.asc";
  String privateKeyPassword = "key password";
  String encryptedFile = @"c:\encrypted.pgp";
 
  PGPInspectLib inspectLib = new PGPInspectLib();
  ContentItem[] files = inspectLib.ListOpenPgpFile(encryptedFile, _
                                                   privateKey, _
                                                   privateKeyPassword);
  Console.WriteLine(encryptedFile + " contains:");
  foreach (ContentItem file in files) 
  {
	Console.Write(file.FileName);
	Console.Write(file.IsDirectory ? "[dir]" : "[file]"); 
        Console.WriteLine(file.ModificationTime); 
  } 
 } 
}


The value of file.FileName printed with the code above is what you need.

Kind Regards
Peter Kalef
Technical Support
DidiSoft Inc | Phone: +1-256-907-7816 | Fax: +1-256-907-7816 | Web: www.didisoft.com
Reply all
Reply to author
Forward
0 new messages