Search code examples
encryptionbouncycastlegnupgpgpopenpgp

How to get rid of the original file path instead of name in PGP encryption with ChoPGP library?


I tried PGP encrypting a file in ChoPGP library. At the end of the process it shows embedded file name along with the whole original file name path.

But I thought it will show only the filename without the whole path. Which I intend to work on and figure out a way to do so?

Doing the following:

            using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt())
        {
            pgp.EncryptFile(@"\\appdevtest\c$\appstest\Transporter\test\Test.txt",
                @"\\appdevtest\c$\appstest\Transporter\test\OSCTestFile_ChoPGP.gpg",
                @"\\appdevtest\c$\appstest\Transporter\pgpKey\PublicKey\atorres\atorres_publicKey.asc", 
                true, 
                true);
        }
  • which will result in:

enter image description here

  • But I would like to only extract the Test.txt in the end something like this:

enter image description here


Solution

  • Looking at this line from the ChoPGP sources: https://github.com/Cinchoo/ChoPGP/blob/7152c7385022823013324408e84cb7e25d33c3e7/ChoPGP/ChoPGPEncryptDecrypt.cs#L221

    You may find out that it uses internal function GetFileName, which ends up with this for the FileStream: return ((FileStream)stream).Name;.

    And this one, according to documentation, Gets the absolute path of the file opened in the FileStream..

    So you should either make fork of ChoPGP and modify this line to extract just filename, or submit a pull request to the ChoPGP. Btw, it's just a wrapper around the BouncyCastle so you may use that instead.