Can anyone please explain the correct way to produce ASCII armored PGP encrypted output? Using below code, I produce binary encrypted files, and I can decrypt them. But if ASCIIArmor == true, that produced what looked like a partial output, which I could not decrypt. Am I applying ArmoredOutputStream() to a wrong stream?
static Stream ChainEncryptedOut(Stream outputStream) { PgpEncryptedDataGenerator encryptedDataGenerator = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.TripleDes, new SecureRandom()); encryptedDataGenerator.AddMethod(EncryptionKey); return encryptedDataGenerator.Open(ASCIIArmor ? new ArmoredOutputStream(outputStream) : outputStream, new byte[BufferSize]); } static Stream ChainLiteralOut(Stream encryptedOut, FileInfo file, long length) { return new PgpLiteralDataGenerator().Open(encryptedOut, PgpLiteralData.Binary, file == null ? "" : file.Name, length, DateTime.Now); } Calling code: using (Stream encryptedOut = ChainEncryptedOut(outputStream)) { using (Stream literalOut = ChainLiteralOut(encryptedOut, unencryptedFileInfo, inputStream.Length)) { WriteOutput(literalOut, inputStream); } } When encrypting “Hello World”, the binary output is 575 bytes long, and the ASCII armored output is 844 bytes long, looking as follows: -----BEGIN PGP MESSAGE----- Version: BCPG C# v1.8.1.0 hQIMA0MeHw19BxFFAQ//Yiy3OgGExwCPPlrsjc8OegjZ83CY/Ks3vDCo2PSNUfk9 hQWWphAcXobLwWiKKsrSpf8+O6QcHY8AHCZd+5+GTVDWlXEDPiQTwnmnHmgqMGuQ M+p92dLX8UW19dMfHN0Y1m9dDgqUkCZm0NXILdwZ2vF4CWHa7stgRhPJaDLkGW8Q KaXmaIq5OoOc6kz7ugMekezQe+8TGDf4ByFxKCbH+dD1dHicw3hVeqsQwot6X1JY j3+OLxzXoAiq/Tsv18f4WRjpGIR76+lbLLQs3K0PN8qN1JpktE9W2NBiwsM8G6fU 03PK5s4TwYBtKrhRir3fbf9q8nGO/YL+IaYydcjkfc2PHxhLNDgkN3k6ArvXc0de AWJg+zTdbzA/k2SlVEQuoUfd8j3pXKYNriggDfJUXVcUC8nxZ82+H9MaM7dqeTZA ljs4SDf2fYKCUdftSv1O2hqDORvf3sUH5L0ftgYUCRnnHbVZE8fPVIOjtbWH+7NS 5YTB5cFQxtOb7BOjVau23ZqQYkfhOUdIMEhGyk3ugg1YVgAGtI0TuQHXmHFNTRFI O3oMBtmp1TytJscbiYy2h95GrQcqJMDs9zJkZXxYicF/9hvcmpDrUvb0J/nwt8bC mc87xK723V47O70gU01QGGdnABjPn1tPQHz48v0FkACJdNNDSx81Xzv14bZlaO7J LvbUgmGuz7nNCFbeR9ZgQiirCWYMnnoC3RdqGbXvzWg+7fkEM5b//H90JIQ8 Should there be more output? Should it be closed with something like “----END PGP MESSAGE----“? Thank you! Alex