Preferred cypher for pgp encryption in Java

By default all encrypt methods use CAST 5 as an internal symmetric key encryption algorithm, form maximum compatibility with other OpenPGP solutions. This can be changed through a setter method PGPLib.setCypher( string cypher). The accepted values that can be passed for the cypher parameter are listed in the CypherAlgorithm interface:

CypherAlgorithm.TRIPLE_DES;
CypherAlgorithm.String CAST5;
CypherAlgorithm.String BLOWFISH;
CypherAlgorithm.String AES_128;
CypherAlgorithm.String AES_192;
CypherAlgorithm.String AES_256;
CypherAlgorithm.String TWOFISH;
CypherAlgorithm.String DES;
CypherAlgorithm.String SAFER;
CypherAlgorithm.String IDEA;

Here is how to set the default symmetric algorithm to 128 bit AES :

PGPLib pgp = new PGPLib();
pgp.setCypher(CypherAlgorithm.AES_128);

Each subsequent call to encrypt or sign and encrypt will use the new algorithm, but only for the current instance of the library.

Have in mind that if the public key we use for encryption does not support the preferred symmetric algorithm, then the first cypher from this key preferred list will be used (each OpenPGP key stores internally it’s algorithm preferences).