The OpenPGP archive format contains internal information for the encrypted data like file name, modification date, and content type.
The OpenPGP standard currently supports three types of content type : binary, text and UTF-8 (seldom used in practice).
The default is binary. In this chapter we will demonstrate how to change this behavior.
Specifying explicitly the content type
In most cases you don’t have to bother to change the default content type before performing encryption.
The only case when you have to set it explicitly is when your recipient expects textual data and is using an Operating System with different line ending characters. This way when they decrypt it, their OpenPGP software will correct the line endings automatically for their operating system.
The example below demonstrates how to explicitly set the content type in C# and VB.NET.
C# example
using System; using DidiSoft.Pgp; public class SetContentTypeDemo { public void Demo() { // create an instance of the library PGPLib pgp = new PGPLib(); // change explicitly the content type pgp.ContentType = ContentDataType.Text; // now we can call pgp.Encrypt ... } } |
VB.NET example
Imports System.IO Imports DidiSoft.Pgp Public Class SetContentTypeDemo Public Sub Demo() ' create an instance of the library Dim pgp As New PGPLib() ' change explicitly the content type pgp.ContentType = ContentDataType.Text ' now we can call pgp.Encrypt ... End Sub End Class |
Summary
In this chapter we have illustrated how to explicitly set the content type before performing OpenPGP encryption.
Properties used:
Property | Type | Description |
PGPLib.ContentType | DidiSoft.Pgp.ContentDataType | Sets explicitly the content type for the OpenPGP archives created by the library.Default is binary |