-1

I am working on a file processing automation program. One of the function is to decrypt pgp file. I am using a code snippet written by maruthi pallamalli ( https://code.msdn.microsoft.com/windowsdesktop/Pretty-Good-Privacy-using-4f473c67#content) to do the decryption. However, I am having problem determiningenter code here the original file type dynamically so I can set the correct output file path.

  public static void Decrypt(Stream inputStream, Stream privateKeyStream, string passPhrase, string **outputFile**)
    {
        try
        {
            PgpObjectFactory pgpF = null;
            ....
        }
     }

1 Answers1

0

If a file is encrypted, you will not be able to determine the file type without decrypting it first.

The best way to deal with this depends on what your software is doing. If you can store the data in a trustworthy way, you can store the original file type outside of the encrypted data. You should only do this if there is no way for someone to tamper with this data.

If you can't store the file type in a trustworthy way, one option might be to store the file type and an HMAC of the file type and the encrypted data together. The HMAC lets you verify that the file type has not been tampered with, since you can only generate an HMAC if you know the secret key.

Stephen Jennings
  • 12,494
  • 5
  • 47
  • 66