I work at a small company where a business user gets encrypted files from a client and decrypts them manually using gpg. I think the user imported the private key long ago using
gpg --import privatekey.asc
After that, all he does with an encrypted file is:
gpg -d -o decryptedFile.txt encryptedFile.gpg
We want to automate this process, and I’m using C# and the BouncyCastle.Cryptography package (v 2.4.0) to do it, I know that’s different from gpg, but my first approach is to use a package, I don’t want to invoke the gpg utility from my C# application using the System.Diagnostics.Process class.
Here’s the beginning of the code I have to decrypt the file:
private static void Decrypt(Stream inputStream, Stream outputStream, Stream privateKeyStream, char[] passPhrase)
{
inputStream = PgpUtilities.GetDecoderStream(inputStream);
PgpObjectFactory pgpF = new(inputStream);
PgpEncryptedDataList encryptedDataList;
PgpObject o = pgpF.NextPgpObject();
....
}
The call to NextPgpObject() errors with message “unknown packet type encountered: 20”. Given that the file can be successfully decrypted via the command line, I’m sure it’s not a malformed pgp file, so why is my program failing? It hasn’t even tried to decrypt the file yet.