mattosaurus / PgpCore

.NET Core class library for using PGP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Size differences between files encrypted with PGPCore and files encrypted with PGP command line

MB34 opened this issue · comments

commented

We have noticed that the files that are encrypted using PGPCore are significantly larger than files encrypted with command line PGP.

For a 22KB (22,304 bytes) file, the encrypted file size for one encrypted by command line PGP is 7.98KB (8,178 bytes)
But the exact same file encrypted using PGPCore is 78.2KB (80,087 bytes)

Can you explain this ten fold increase in file size?

It's probably because PGP is compressing the message and the PGPCore default is not to compress it.

https://github.com/mattosaurus/PgpCore#compressionalgorithm

There may also be a difference in armoured vs binary output.

commented

Well, how do I change the CompressionAlgorithm?

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public async Task DecryptFileAndVerifyAsync_DecryptCompressedUnsignedFile(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
TestFactory testFactory2 = new TestFactory();
await testFactory.ArrangeAsync(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKeyFileInfo);
EncryptionKeys decryptionKeys = new EncryptionKeys(testFactory.PrivateKeyFileInfo, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys)
{
CompressionAlgorithm = CompressionAlgorithmTag.Zip
};
PGP pgpDecrypt = new PGP(decryptionKeys);
// Act
await pgpEncrypt.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath);
var ex = await Assert.ThrowsAsync<PgpException>(async () => await pgpDecrypt.DecryptFileAndVerifyAsync(testFactory.EncryptedContentFilePath,
testFactory.DecryptedContentFilePath));
// Assert
Assert.Equal("File was not signed.", ex.Message);
Assert.True(testFactory.EncryptedContentFileInfo.Exists);
Assert.True(testFactory.DecryptedContentFileInfo.Exists);
Assert.Equal(string.Empty, testFactory.DecryptedContent.Trim());
// Teardown
testFactory.Teardown();
}

commented

THX, Got it working