By default OpenPGP Library for Java marks the content in the produced OpenPGP archives as binary data.
As of version 2.6.1 the library supports the content type to be explicitly changed to text.
In this chapter we demonstrate this with short examples.
Changing the content type
Marking the content type of an OpenPGP archive as text is very useful when exchanging encrypted textual data between systems with different line endings. For example if the source system is Windows and the recipient system is Unix based they have different line ending characters.
Fortunately the OpenPGP specification has specified that textual data can be exchanged transparently. The sender’s OpenPGP software transforms the line endings in the produced OpenPGP file in a system neutral form. At the destination the receiving OpenPGP software transforms the system neutral line endings into the default line ending of the target system.
Let’s see with a short example how to instruct the library to produce content marked as text:
PGPLib pgp = new PGPLib(); pgp.setContentType(ContentDataType.TEXT);
Producing OpenPGP content with the thus initialized PGPLib instance will be marked as text.
We can set back the default binary behavior for subsequent encryption/signing calls with the line:
PGPLib pgp = new PGPLib(); pgp.setContentType(ContentDataType.BINARY);
There is also an additional content type UTF8 which is not used currently by the major OpenPGP software vendors. In the future this may change.
In this chapter we have discussed how to prepare the library class PGPLib to mark the content of the produced OpenPGP archives as textual. This is very useful when exchanging textual data between different Operating Systems with different line endings.
The default behavior is to mark the content as binary.