From 131e9d357df27141fb7ee673c12a36bf2b7d6d78 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Fri, 8 Dec 2023 15:00:41 +0000 Subject: [PATCH 1/2] Add old pgp format support --- PgpCore/Abstractions/IPGP.EncryptAsync.cs | 24 +++++----- PgpCore/Abstractions/IPGP.EncryptSync.cs | 24 +++++----- PgpCore/Abstractions/IPGP.SignAsync.cs | 12 ++--- PgpCore/Abstractions/IPGP.SignSync.cs | 12 ++--- PgpCore/Helpers/Utilities.cs | 40 ++++++++++------- PgpCore/PGP.EncryptAsync.cs | 54 ++++++++++++++--------- PgpCore/PGP.EncryptSync.cs | 54 ++++++++++++++--------- PgpCore/PGP.SignAsync.cs | 25 ++++++----- PgpCore/PGP.SignSync.cs | 28 +++++++----- PgpCore/PGP.cs | 40 ++++++++--------- 10 files changed, 177 insertions(+), 136 deletions(-) diff --git a/PgpCore/Abstractions/IPGP.EncryptAsync.cs b/PgpCore/Abstractions/IPGP.EncryptAsync.cs index 97cbc74..79f8936 100644 --- a/PgpCore/Abstractions/IPGP.EncryptAsync.cs +++ b/PgpCore/Abstractions/IPGP.EncryptAsync.cs @@ -7,18 +7,18 @@ namespace PgpCore.Abstractions { public interface IEncryptAsync : IDisposable { - Task EncryptAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptAndSignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptAndSignAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptAndSignAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); + Task EncryptAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptAndSignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptAndSignAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptAndSignAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); - Task EncryptFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptArmoredStringAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptFileAndSignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptStreamAndSignAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - Task EncryptArmoredStringAndSignAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); + Task EncryptFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptArmoredStringAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptFileAndSignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptStreamAndSignAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task EncryptArmoredStringAndSignAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); } } \ No newline at end of file diff --git a/PgpCore/Abstractions/IPGP.EncryptSync.cs b/PgpCore/Abstractions/IPGP.EncryptSync.cs index ece0ecc..2dd8748 100644 --- a/PgpCore/Abstractions/IPGP.EncryptSync.cs +++ b/PgpCore/Abstractions/IPGP.EncryptSync.cs @@ -8,18 +8,18 @@ namespace PgpCore.Abstractions { public interface IEncryptSync : IDisposable { - void Encrypt(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - void Encrypt(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - string Encrypt(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - void EncryptAndSign(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - void EncryptAndSign(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - string EncryptAndSign(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); + void Encrypt(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void Encrypt(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + string Encrypt(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void EncryptAndSign(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void EncryptAndSign(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + string EncryptAndSign(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); - void EncryptFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - void EncryptStream(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - string EncryptArmoredString(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - void EncryptFileAndSign(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - void EncryptStreamAndSign(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); - string EncryptArmoredStringAndSign(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null); + void EncryptFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void EncryptStream(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + string EncryptArmoredString(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void EncryptFileAndSign(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void EncryptStreamAndSign(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); + string EncryptArmoredStringAndSign(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false); } } diff --git a/PgpCore/Abstractions/IPGP.SignAsync.cs b/PgpCore/Abstractions/IPGP.SignAsync.cs index aa75a10..5bc44e4 100644 --- a/PgpCore/Abstractions/IPGP.SignAsync.cs +++ b/PgpCore/Abstractions/IPGP.SignAsync.cs @@ -7,16 +7,16 @@ namespace PgpCore.Abstractions { public interface ISignAsync : IDisposable { - Task SignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null); - Task SignAsync(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null); - Task SignAsync(string input, bool armor = true, string name = null, IDictionary headers = null); + Task SignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task SignAsync(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task SignAsync(string input, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); Task ClearSignAsync(FileInfo inputFile, FileInfo outputFile, IDictionary headers = null); Task ClearSignAsync(Stream inputStream, Stream outputStream, IDictionary headers = null); Task ClearSignAsync(string input, IDictionary headers = null); - Task SignFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null); - Task SignStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null); - Task SignArmoredStringAsync(string input, bool armor = true, string name = null, IDictionary headers = null); + Task SignFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task SignStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + Task SignArmoredStringAsync(string input, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); Task ClearSignFileAsync(FileInfo inputFile, FileInfo outputFile, IDictionary headers = null); Task ClearSignStreamAsync(Stream inputStream, Stream outputStream, IDictionary headers = null); Task ClearSignArmoredStringAsync(string input, IDictionary headers = null); diff --git a/PgpCore/Abstractions/IPGP.SignSync.cs b/PgpCore/Abstractions/IPGP.SignSync.cs index b1afcff..d67ca46 100644 --- a/PgpCore/Abstractions/IPGP.SignSync.cs +++ b/PgpCore/Abstractions/IPGP.SignSync.cs @@ -8,16 +8,16 @@ namespace PgpCore.Abstractions { public interface ISignSync : IDisposable { - void Sign(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null); - void Sign(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null); - string Sign(string input, bool armor = true, string name = null, IDictionary headers = null); + void Sign(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void Sign(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + string Sign(string input, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); void ClearSign(FileInfo inputFile, FileInfo outputFile, IDictionary headers = null); void ClearSign(Stream inputStream, Stream outputStream, IDictionary headers = null); string ClearSign(string input, IDictionary headers = null); - void SignFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null); - void SignStream(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null); - string SignArmoredString(string input, bool armor = true, string name = null, IDictionary headers = null); + void SignFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + void SignStream(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); + string SignArmoredString(string input, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false); void ClearSignFile(FileInfo inputFile, FileInfo outputFile, IDictionary headers = null); void ClearSignStream(Stream inputStream, Stream outputStream, IDictionary headers = null); string ClearSignArmoredString(string input, IDictionary headers = null); diff --git a/PgpCore/Helpers/Utilities.cs b/PgpCore/Helpers/Utilities.cs index 6d2c682..12a579d 100644 --- a/PgpCore/Helpers/Utilities.cs +++ b/PgpCore/Helpers/Utilities.cs @@ -317,9 +317,10 @@ public static KeyParameter MakeKeyFromPassPhrase( public static async Task WriteFileToLiteralDataAsync( Stream output, char fileType, - FileInfo file) + FileInfo file, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, file.Name, file.Length, file.LastWriteTime); await PipeFileContentsAsync(file, pOut, 4096); } @@ -328,9 +329,10 @@ public static async Task WriteFileToLiteralDataAsync( public static void WriteFileToLiteralData( Stream output, char fileType, - FileInfo file) + FileInfo file, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, file.Name, file.Length, file.LastWriteTime); PipeFileContents(file, pOut, 4096); } @@ -340,9 +342,10 @@ public static async Task WriteFileToLiteralDataAsync( Stream output, char fileType, FileInfo file, - byte[] buffer) + byte[] buffer, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, file.Name, file.LastWriteTime, buffer); await PipeFileContentsAsync(file, pOut, buffer.Length); } @@ -352,9 +355,10 @@ public static void WriteFileToLiteralData( Stream output, char fileType, FileInfo file, - byte[] buffer) + byte[] buffer, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, file.Name, file.LastWriteTime, buffer); PipeFileContents(file, pOut, buffer.Length); } @@ -363,9 +367,10 @@ public static async Task WriteStreamToLiteralDataAsync( Stream output, char fileType, Stream input, - string name) + string name, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, name, input.Length, DateTime.Now); await PipeStreamContentsAsync(input, pOut, 4096); } @@ -374,9 +379,10 @@ public static void WriteStreamToLiteralData( Stream output, char fileType, Stream input, - string name) + string name, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, name, input.Length, DateTime.Now); PipeStreamContents(input, pOut, 4096); } @@ -386,9 +392,10 @@ public static async Task WriteStreamToLiteralDataAsync( char fileType, Stream input, byte[] buffer, - string name) + string name, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, name, DateTime.Now, buffer); await PipeStreamContentsAsync(input, pOut, buffer.Length); } @@ -398,9 +405,10 @@ public static void WriteStreamToLiteralData( char fileType, Stream input, byte[] buffer, - string name) + string name, + bool oldFormat) { - PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(oldFormat); Stream pOut = lData.Open(output, fileType, name, DateTime.Now, buffer); PipeStreamContents(input, pOut, buffer.Length); } diff --git a/PgpCore/PGP.EncryptAsync.cs b/PgpCore/PGP.EncryptAsync.cs index a01ded0..a577a94 100644 --- a/PgpCore/PGP.EncryptAsync.cs +++ b/PgpCore/PGP.EncryptAsync.cs @@ -26,13 +26,15 @@ public partial class PGP : IEncryptAsync /// True, to perform integrity packet check on input file. Otherwise, false /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public async Task EncryptAsync( FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputFile == null) throw new ArgumentException("InputFile"); @@ -49,7 +51,7 @@ public async Task EncryptAsync( using (FileStream inputStream = inputFile.OpenRead()) using (Stream outputStream = outputFile.OpenWrite()) - await EncryptAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + await EncryptAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); } /// @@ -61,13 +63,15 @@ public async Task EncryptAsync( /// True, to perform integrity packet check on input file. Otherwise, false /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public async Task EncryptAsync( Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputStream == null) throw new ArgumentException("InputStream"); @@ -102,14 +106,14 @@ public async Task EncryptAsync( using (Stream @out = pk.Open(outputStream, new byte[1 << 16])) using (Stream compressedStream = new PgpCompressedDataGenerator(CompressionAlgorithm).Open(@out, new byte[1 << 16])) { - await Utilities.WriteStreamToLiteralDataAsync(compressedStream, FileTypeToChar(), inputStream, name); + await Utilities.WriteStreamToLiteralDataAsync(compressedStream, FileTypeToChar(), inputStream, name, oldFormat); } } else { using (Stream @out = pk.Open(outputStream, new byte[1 << 16])) { - await Utilities.WriteStreamToLiteralDataAsync(@out, FileTypeToChar(), inputStream, name); + await Utilities.WriteStreamToLiteralDataAsync(@out, FileTypeToChar(), inputStream, name, oldFormat); } } @@ -127,12 +131,14 @@ public async Task EncryptAsync( /// True, to perform integrity packet check on input file. Otherwise, false /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public async Task EncryptAsync( string input, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (string.IsNullOrEmpty(name)) name = DefaultFileName; @@ -142,17 +148,17 @@ public async Task EncryptAsync( using (Stream inputStream = await input.GetStreamAsync()) using (Stream outputStream = new MemoryStream()) { - await EncryptAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + await EncryptAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); outputStream.Seek(0, SeekOrigin.Begin); return await outputStream.GetStringAsync(); } } - public async Task EncryptFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => await EncryptAsync(inputFile, outputFile, armor, withIntegrityCheck, name, headers); + public async Task EncryptFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await EncryptAsync(inputFile, outputFile, armor, withIntegrityCheck, name, headers, oldFormat); - public async Task EncryptStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => await EncryptAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + public async Task EncryptStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await EncryptAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); - public async Task EncryptArmoredStringAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => await EncryptAsync(input, armor, withIntegrityCheck, name, headers); + public async Task EncryptArmoredStringAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await EncryptAsync(input, armor, withIntegrityCheck, name, headers, oldFormat); #endregion EncryptAsync @@ -168,13 +174,15 @@ public async Task EncryptAsync( /// True to include integrity packet during signing /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public async Task EncryptAndSignAsync( FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputFile == null) throw new ArgumentException("InputFilePath"); @@ -196,11 +204,11 @@ public async Task EncryptAndSignAsync( { using (ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - await OutputEncryptedAsync(inputFile, armoredOutputStream, withIntegrityCheck, name); + await OutputEncryptedAsync(inputFile, armoredOutputStream, withIntegrityCheck, name, oldFormat); } } else - await OutputEncryptedAsync(inputFile, outputStream, withIntegrityCheck, name); + await OutputEncryptedAsync(inputFile, outputStream, withIntegrityCheck, name, oldFormat); } } @@ -214,13 +222,15 @@ public async Task EncryptAndSignAsync( /// True to include integrity packet during signing /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public async Task EncryptAndSignAsync( Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputStream == null) throw new ArgumentException("InputStream"); @@ -241,11 +251,11 @@ public async Task EncryptAndSignAsync( { using (var armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - await OutputEncryptedAsync(inputStream, armoredOutputStream, withIntegrityCheck, name); + await OutputEncryptedAsync(inputStream, armoredOutputStream, withIntegrityCheck, name, oldFormat); } } else - await OutputEncryptedAsync(inputStream, outputStream, withIntegrityCheck, name); + await OutputEncryptedAsync(inputStream, outputStream, withIntegrityCheck, name, oldFormat); } /// @@ -257,12 +267,14 @@ public async Task EncryptAndSignAsync( /// True to include integrity packet during signing /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public async Task EncryptAndSignAsync( string input, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (string.IsNullOrEmpty(name)) name = DefaultFileName; @@ -272,17 +284,17 @@ public async Task EncryptAndSignAsync( using (Stream inputStream = await input.GetStreamAsync()) using (Stream outputStream = new MemoryStream()) { - await EncryptAndSignAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + await EncryptAndSignAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); outputStream.Seek(0, SeekOrigin.Begin); return await outputStream.GetStringAsync(); } } - public async Task EncryptFileAndSignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => await EncryptAndSignAsync(inputFile, outputFile, armor, withIntegrityCheck, name, headers); + public async Task EncryptFileAndSignAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await EncryptAndSignAsync(inputFile, outputFile, armor, withIntegrityCheck, name, headers, oldFormat); - public async Task EncryptStreamAndSignAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => await EncryptAndSignAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + public async Task EncryptStreamAndSignAsync(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await EncryptAndSignAsync(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); - public async Task EncryptArmoredStringAndSignAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => await EncryptAndSignAsync(input, armor, withIntegrityCheck, name, headers); + public async Task EncryptArmoredStringAndSignAsync(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await EncryptAndSignAsync(input, armor, withIntegrityCheck, name, headers, oldFormat); #endregion EncryptAndSignAsync } diff --git a/PgpCore/PGP.EncryptSync.cs b/PgpCore/PGP.EncryptSync.cs index d97b541..b3364dc 100644 --- a/PgpCore/PGP.EncryptSync.cs +++ b/PgpCore/PGP.EncryptSync.cs @@ -24,13 +24,15 @@ public partial class PGP : IEncryptSync /// True, to perform integrity packet check on input file. Otherwise, false /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public void Encrypt( FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputFile == null) throw new ArgumentException("InputFile"); @@ -47,7 +49,7 @@ public void Encrypt( using (FileStream inputStream = inputFile.OpenRead()) using (Stream outputStream = outputFile.OpenWrite()) - Encrypt(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + Encrypt(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); } /// @@ -59,13 +61,15 @@ public void Encrypt( /// True, to perform integrity packet check on input file. Otherwise, false /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public void Encrypt( Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputStream == null) throw new ArgumentException("InputStream"); @@ -101,14 +105,14 @@ public void Encrypt( using (Stream @out = pk.Open(outputStream, new byte[1 << 16])) using (Stream compressedStream = new PgpCompressedDataGenerator(CompressionAlgorithm).Open(@out, new byte[1 << 16])) { - Utilities.WriteStreamToLiteralData(compressedStream, FileTypeToChar(), inputStream, name); + Utilities.WriteStreamToLiteralData(compressedStream, FileTypeToChar(), inputStream, name, oldFormat); } } else { using (Stream @out = pk.Open(outputStream, new byte[1 << 16])) { - Utilities.WriteStreamToLiteralData(@out, FileTypeToChar(), inputStream, name); + Utilities.WriteStreamToLiteralData(@out, FileTypeToChar(), inputStream, name, oldFormat); } } @@ -126,12 +130,14 @@ public void Encrypt( /// True, to perform integrity packet check on input file. Otherwise, false /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public string Encrypt( string input, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (string.IsNullOrEmpty(name)) name = DefaultFileName; @@ -141,17 +147,17 @@ public string Encrypt( using (Stream inputStream = input.GetStream()) using (Stream outputStream = new MemoryStream()) { - Encrypt(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + Encrypt(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); outputStream.Seek(0, SeekOrigin.Begin); return outputStream.GetString(); } } - public string EncryptArmoredString(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => Encrypt(input, armor, withIntegrityCheck, name, headers); + public string EncryptArmoredString(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => Encrypt(input, armor, withIntegrityCheck, name, headers, oldFormat); - public void EncryptFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => Encrypt(inputFile, outputFile, armor, withIntegrityCheck, name, headers); + public void EncryptFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => Encrypt(inputFile, outputFile, armor, withIntegrityCheck, name, headers, oldFormat); - public void EncryptStream(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => Encrypt(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + public void EncryptStream(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => Encrypt(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); #endregion Encrypt @@ -165,13 +171,15 @@ public string Encrypt( /// True, means a binary data representation as an ASCII-only text. Otherwise, false /// True to include integrity packet during signing /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public void EncryptAndSign( FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputFile == null) throw new ArgumentException("InputFilePath"); @@ -193,11 +201,11 @@ public void EncryptAndSign( { using (var armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - OutputEncrypted(inputFile, armoredOutputStream, withIntegrityCheck, name); + OutputEncrypted(inputFile, armoredOutputStream, withIntegrityCheck, name, oldFormat); } } else - OutputEncrypted(inputFile, outputStream, withIntegrityCheck, name); + OutputEncrypted(inputFile, outputStream, withIntegrityCheck, name, oldFormat); } } @@ -210,13 +218,15 @@ public void EncryptAndSign( /// True to include integrity packet during signing /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public void EncryptAndSign( Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputStream == null) throw new ArgumentException("InputStream"); @@ -237,11 +247,11 @@ public void EncryptAndSign( { using (var armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - OutputEncrypted(inputStream, armoredOutputStream, withIntegrityCheck, name); + OutputEncrypted(inputStream, armoredOutputStream, withIntegrityCheck, name, oldFormat); } } else - OutputEncrypted(inputStream, outputStream, withIntegrityCheck, name); + OutputEncrypted(inputStream, outputStream, withIntegrityCheck, name, oldFormat); } /// @@ -251,12 +261,14 @@ public void EncryptAndSign( /// True to include integrity packet during signing /// Name of encrypted file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public string EncryptAndSign( string input, bool armor = true, bool withIntegrityCheck = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (string.IsNullOrEmpty(name)) name = DefaultFileName; @@ -266,17 +278,17 @@ public string EncryptAndSign( using (Stream inputStream = input.GetStream()) using (Stream outputStream = new MemoryStream()) { - EncryptAndSign(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + EncryptAndSign(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); outputStream.Seek(0, SeekOrigin.Begin); return outputStream.GetString(); } } - public string EncryptArmoredStringAndSign(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => EncryptAndSign(input, armor, withIntegrityCheck, name, headers); + public string EncryptArmoredStringAndSign(string input, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => EncryptAndSign(input, armor, withIntegrityCheck, name, headers, oldFormat); - public void EncryptFileAndSign(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => EncryptAndSign(inputFile, outputFile, armor, withIntegrityCheck, name, headers); + public void EncryptFileAndSign(FileInfo inputFile, FileInfo outputFile, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => EncryptAndSign(inputFile, outputFile, armor, withIntegrityCheck, name, headers, oldFormat); - public void EncryptStreamAndSign(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null) => EncryptAndSign(inputStream, outputStream, armor, withIntegrityCheck, name, headers); + public void EncryptStreamAndSign(Stream inputStream, Stream outputStream, bool armor = true, bool withIntegrityCheck = true, string name = null, IDictionary headers = null, bool oldFormat = false) => EncryptAndSign(inputStream, outputStream, armor, withIntegrityCheck, name, headers, oldFormat); #endregion EncryptAndSign } diff --git a/PgpCore/PGP.SignAsync.cs b/PgpCore/PGP.SignAsync.cs index 7126578..68146b7 100644 --- a/PgpCore/PGP.SignAsync.cs +++ b/PgpCore/PGP.SignAsync.cs @@ -26,7 +26,8 @@ public async Task SignAsync( FileInfo outputFile, bool armor = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputFile == null) throw new ArgumentException("InputFile"); @@ -48,11 +49,11 @@ public async Task SignAsync( { using (ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - await OutputSignedAsync(inputFile, armoredOutputStream, name); + await OutputSignedAsync(inputFile, armoredOutputStream, name, oldFormat); } } else - await OutputSignedAsync(inputFile, outputStream, name); + await OutputSignedAsync(inputFile, outputStream, name, oldFormat); } } @@ -69,7 +70,8 @@ public async Task SignAsync( Stream outputStream, bool armor = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputStream == null) throw new ArgumentException("InputStream"); @@ -90,11 +92,11 @@ public async Task SignAsync( { using (ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - await OutputSignedAsync(inputStream, armoredOutputStream, name); + await OutputSignedAsync(inputStream, armoredOutputStream, name, oldFormat); } } else - await OutputSignedAsync(inputStream, outputStream, name); + await OutputSignedAsync(inputStream, outputStream, name, oldFormat); } /// @@ -108,7 +110,8 @@ public async Task SignAsync( string input, bool armor = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (string.IsNullOrEmpty(name)) name = DefaultFileName; @@ -118,17 +121,17 @@ public async Task SignAsync( using (Stream inputStream = await input.GetStreamAsync()) using (Stream outputStream = new MemoryStream()) { - await SignAsync(inputStream, outputStream, armor, name, headers); + await SignAsync(inputStream, outputStream, armor, name, headers, oldFormat); outputStream.Seek(0, SeekOrigin.Begin); return await outputStream.GetStringAsync(); } } - public async Task SignFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null) => await SignAsync(inputFile, outputFile, armor, name, headers); + public async Task SignFileAsync(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await SignAsync(inputFile, outputFile, armor, name, headers, oldFormat); - public async Task SignStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null) => await SignAsync(inputStream, outputStream, armor, name, headers); + public async Task SignStreamAsync(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await SignAsync(inputStream, outputStream, armor, name, headers, oldFormat); - public async Task SignArmoredStringAsync(string input, bool armor = true, string name = null, IDictionary headers = null) => await SignAsync(input, armor, name, headers); + public async Task SignArmoredStringAsync(string input, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false) => await SignAsync(input, armor, name, headers, oldFormat); #endregion SignAsync diff --git a/PgpCore/PGP.SignSync.cs b/PgpCore/PGP.SignSync.cs index 48bccf7..37e06b3 100644 --- a/PgpCore/PGP.SignSync.cs +++ b/PgpCore/PGP.SignSync.cs @@ -21,12 +21,14 @@ public partial class PGP : ISignSync /// True, means a binary data representation as an ASCII-only text. Otherwise, false /// Name of signed file in message, defaults to the input file name /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public void Sign( FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputFile == null) throw new ArgumentException("InputFile"); @@ -48,11 +50,11 @@ public void Sign( { using (ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - OutputSigned(inputFile, armoredOutputStream, name); + OutputSigned(inputFile, armoredOutputStream, name, oldFormat); } } else - OutputSigned(inputFile, outputStream, name); + OutputSigned(inputFile, outputStream, name, oldFormat); } } @@ -64,12 +66,14 @@ public void Sign( /// True, means a binary data representation as an ASCII-only text. Otherwise, false /// Name of signed file in message, defaults to the stream name if the stream is a FileStream, otherwise to "name" /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public void Sign( Stream inputStream, Stream outputStream, bool armor = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (inputStream == null) throw new ArgumentException("InputStream"); @@ -90,11 +94,11 @@ public void Sign( { using (ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream, headers)) { - OutputSigned(inputStream, armoredOutputStream, name); + OutputSigned(inputStream, armoredOutputStream, name, oldFormat); } } else - OutputSigned(inputStream, outputStream, name); + OutputSigned(inputStream, outputStream, name, oldFormat); } /// @@ -103,11 +107,13 @@ public void Sign( /// Plain string to be signed /// Name of signed file in message, defaults to "name" /// Optional headers to be added to the output + /// True, to use old format for encryption if you need compatability with PGP 2.6.x. Otherwise, false public string Sign( string input, bool armor = true, string name = null, - IDictionary headers = null) + IDictionary headers = null, + bool oldFormat = false) { if (string.IsNullOrEmpty(name)) name = DefaultFileName; @@ -117,17 +123,17 @@ public string Sign( using (Stream inputStream = input.GetStream()) using (Stream outputStream = new MemoryStream()) { - Sign(inputStream, outputStream, armor, name, headers); + Sign(inputStream, outputStream, armor, name, headers, oldFormat); outputStream.Seek(0, SeekOrigin.Begin); return outputStream.GetString(); } } - public void SignFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null) => Sign(inputFile, outputFile, armor, name, headers); + public void SignFile(FileInfo inputFile, FileInfo outputFile, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false) => Sign(inputFile, outputFile, armor, name, headers, oldFormat); - public void SignStream(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null) => Sign(inputStream, outputStream, armor, name, headers); + public void SignStream(Stream inputStream, Stream outputStream, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false) => Sign(inputStream, outputStream, armor, name, headers, oldFormat); - public string SignArmoredString(string input, bool armor = true, string name = null, IDictionary headers = null) => Sign(input, armor, name, headers); + public string SignArmoredString(string input, bool armor = true, string name = null, IDictionary headers = null, bool oldFormat = false) => Sign(input, armor, name, headers, oldFormat); #endregion Sign diff --git a/PgpCore/PGP.cs b/PgpCore/PGP.cs index e36397d..73c8a22 100644 --- a/PgpCore/PGP.cs +++ b/PgpCore/PGP.cs @@ -53,14 +53,14 @@ public PGP(IEncryptionKeys encryptionKeys) #region OutputEncryptedAsync - private async Task OutputEncryptedAsync(FileInfo inputFile, Stream outputStream, bool withIntegrityCheck, string name) + private async Task OutputEncryptedAsync(FileInfo inputFile, Stream outputStream, bool withIntegrityCheck, string name, bool oldFormat) { using (Stream encryptedOut = ChainEncryptedOut(outputStream, withIntegrityCheck)) { using (Stream compressedOut = ChainCompressedOut(encryptedOut)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name, oldFormat)) { using (FileStream inputFileStream = inputFile.OpenRead()) { @@ -73,14 +73,14 @@ await WriteOutputAndSignAsync(compressedOut, literalOut, inputFileStream, } private async Task OutputEncryptedAsync(Stream inputStream, Stream outputStream, bool withIntegrityCheck, - string name) + string name, bool oldFormat) { using (Stream encryptedOut = ChainEncryptedOut(outputStream, withIntegrityCheck)) { using (Stream compressedOut = ChainCompressedOut(encryptedOut)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name)) + using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) { await WriteOutputAndSignAsync(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -92,14 +92,14 @@ private async Task OutputEncryptedAsync(Stream inputStream, Stream outputStream, #region OutputEncrypted - private void OutputEncrypted(FileInfo inputFile, Stream outputStream, bool withIntegrityCheck, string name) + private void OutputEncrypted(FileInfo inputFile, Stream outputStream, bool withIntegrityCheck, string name, bool oldFormat) { using (Stream encryptedOut = ChainEncryptedOut(outputStream, withIntegrityCheck)) { using (Stream compressedOut = ChainCompressedOut(encryptedOut)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name, oldFormat)) { using (FileStream inputFileStream = inputFile.OpenRead()) { @@ -110,14 +110,14 @@ private void OutputEncrypted(FileInfo inputFile, Stream outputStream, bool withI } } - private void OutputEncrypted(Stream inputStream, Stream outputStream, bool withIntegrityCheck, string name) + private void OutputEncrypted(Stream inputStream, Stream outputStream, bool withIntegrityCheck, string name, bool oldFormat) { using (Stream encryptedOut = ChainEncryptedOut(outputStream, withIntegrityCheck)) { using (Stream compressedOut = ChainCompressedOut(encryptedOut)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name)) + using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) { WriteOutputAndSign(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -129,12 +129,12 @@ private void OutputEncrypted(Stream inputStream, Stream outputStream, bool withI #region OutputSignedAsync - private async Task OutputSignedAsync(FileInfo inputFile, Stream outputStream, string name) + private async Task OutputSignedAsync(FileInfo inputFile, Stream outputStream, string name, bool oldFormat) { using (Stream compressedOut = ChainCompressedOut(outputStream)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name, oldFormat)) { using (FileStream inputFileStream = inputFile.OpenRead()) { @@ -145,12 +145,12 @@ private async Task OutputSignedAsync(FileInfo inputFile, Stream outputStream, st } private async Task OutputSignedAsync(Stream inputStream, Stream outputStream, - string name) + string name, bool oldFormat) { using (Stream compressedOut = ChainCompressedOut(outputStream)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name)) + using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) { await WriteOutputAndSignAsync(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -161,12 +161,12 @@ private async Task OutputSignedAsync(Stream inputStream, Stream outputStream, #region OutputSigned - private void OutputSigned(FileInfo inputFile, Stream outputStream, string name) + private void OutputSigned(FileInfo inputFile, Stream outputStream, string name, bool oldFormat) { using (Stream compressedOut = ChainCompressedOut(outputStream)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputFile, name, oldFormat)) { using (FileStream inputFileStream = inputFile.OpenRead()) { @@ -176,12 +176,12 @@ private void OutputSigned(FileInfo inputFile, Stream outputStream, string name) } } - private void OutputSigned(Stream inputStream, Stream outputStream, string name) + private void OutputSigned(Stream inputStream, Stream outputStream, string name, bool oldFormat) { using (Stream compressedOut = ChainCompressedOut(outputStream)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name)) + using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) { WriteOutputAndSign(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -387,9 +387,9 @@ private Stream ChainCompressedOut(Stream encryptedOut) #region ChainLiteralOut - private Stream ChainLiteralOut(Stream compressedOut, FileInfo file, string name) + private Stream ChainLiteralOut(Stream compressedOut, FileInfo file, string name, bool oldFormat) { - PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(oldFormat); return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, file.Length, DateTime.UtcNow); } @@ -398,9 +398,9 @@ private Stream ChainLiteralOut(Stream compressedOut, FileInfo file, string name) #region ChainLiteralStreamOut - private Stream ChainLiteralStreamOut(Stream compressedOut, Stream inputStream, string name) + private Stream ChainLiteralStreamOut(Stream compressedOut, Stream inputStream, string name, bool oldFormat) { - PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(); + PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(oldFormat); return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, inputStream.Length, DateTime.UtcNow); } From 3d51eabcc6f63d84caed4d5ccbaf1fee4c2e20f2 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Fri, 8 Dec 2023 15:01:37 +0000 Subject: [PATCH 2/2] Update version --- PgpCore/PgpCore.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PgpCore/PgpCore.csproj b/PgpCore/PgpCore.csproj index a9485ce..9e6ef15 100644 --- a/PgpCore/PgpCore.csproj +++ b/PgpCore/PgpCore.csproj @@ -10,10 +10,10 @@ https://github.com/mattosaurus/PgpCore https://github.com/mattosaurus/PgpCore PGP .NET Core - 6.1.0.0 + 6.2.0.0 6.0.0.0 - 6.1.0 - v6.1.0 - Add inspect methods + 6.2.0 + v6.2.0 - Add old PGP format support MIT true true