Preferred compression for pgp data in C# and VB.NET

By default DidiSoft OpenPGP Library for .NET uses ZIP compression when encrypting and signing data. This can be changed through the property PGPLib.Compression. The supported options are listed in the CompressionAlgorithm enum:

CompressionAlgorithm.ZIP
CompressionAlgorithm.ZLIB
CompressionAlgorithm.BZIP2 
CompressionAlgorithm.UNCOMPRESSED

The change has effect only on the current instance of the PGPLib class. For each new instance the preferred compression should be set explicitly. The example below shows how to set the compression to ZLib:

C# code

PGPLib pgp = new PGPLib();
pgp.Compression = CompressionAlgorithm.ZLIB;

VB.NET code

Dim pgp As New PGPLib()
pgp.Compression = CompressionAlgorithm.ZLIB

Please note that by default the library will ignore this setting if the public key used for encryption doesn’t have the specified compression in its preferred compression algorithms list (a special signature inside the key). In order to explicitly always use the value of this setting a new property of the PGPLib class has to be turned on (available as of version 1.7.10.3):

C# example

PGPLib pgp = new PGPLib();
pgp.OverrideKeyAlgorithmPreferences = true;

VB.NET example

Dim pgp As New PGPLib()
pgp.OverrideKeyAlgorithmPreferences = True