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

We can change the preferred symmetric encryption algorithm (cypher) used by DidiSoft OpenPGP Library for .NET through the Cypher property of the PGPLib class. By default CAST 5 symmetric encryption algorithm is used.

The example below demonstrates how to set explicitly a preferred symmetric encryption algorithm for an instance of the library:

C# example

PGPLib pgp = new PGPLib();
pgp.OverrideKeyAlgorithmPreferences = true;
pgp.Cypher = CypherAlgorithm.AES_128;

VB.NET example

Dim pgp As New PGPLib()
pgp.OverrideKeyAlgorithmPreferences = True
pgp.Cypher = CypherAlgorithm.AES_128

The change has effect only on the current instance of the library and will have effect on subsequent calls to all encryption and one pass signing and encryption methods.

Without setting the OverrideKeyAlgorithmPreferences property the library will ignore this setting if the public key used for encryption does not list this algorithm in it’s preferred cyphers list (most OpenPGP public key holds such an information internally in a special signature). In that case the library will automatically pick the first algorithm from the public key list.

Below is a list of the supported symmetric key algorithms:

CypherAlgorithm.TRIPLE_DES
CypherAlgorithm.CAST5
CypherAlgorithm.BLOWFISH
CypherAlgorithm.AES_128
CypherAlgorithm.AES_192
CypherAlgorithm.AES_256
CypherAlgorithm.TWOFISH
CypherAlgorithm.DES
CypherAlgorithm.SAFER
CypherAlgorithm.IDEA
CypherAlgorithm.CAMELLIA_128
CypherAlgorithm.CAMELLIA_192
CypherAlgorithm.CAMELLIA_256

 

The Camellia ciphers were added in version 1.8.2.2.

You may also check how to set explicitly the hashing and compression algorithms for the OpenPGP data packet.