The OpenPGP ASCII armored output format contains usually at the beginning a Version header line and optionally other comment lines. With OpenPGP Library for .NET it looks like:
-----BEGIN PGP MESSAGE-----
Version: DidiSoft OpenPGP Library for .NET / BCPG C# v1.7.5086.29061
Other OpenPGP software products usually include some branding in that Version line. For example in GnuPG/gpg it is :
Version: GnuPG v1.4.9 (MingW32)
There may be situations when you would like to customize the header lines. In this chapter we are going to demonstrate how to achieve this.
Table of Contents
1. Customizing the Version header line
The Version header line customization is performed by setting the AsciiVersionHeader property to a desired value. Below is an example that demonstrates this:
C# example
PGPLib pgp = new PGPLib(); pgp.AsciiVersionHeader = "ACME OpenPGP software"; |
VB.NET example
Dim pgp As New PGPLib() pgp.AsciiVersionHeader = "ACME OpenPGP software" |
After setting the AsciiVersionHeader property on subsequent method calls that produce ASCII armored output the Version header line will look like:
-----BEGIN PGP MESSAGE-----
Version: ACME OpenPGP software
The same property is available in the KeyStore, KeyPairInformaton and RevocationLib classes. It shall be set explicitly with your own desired version header on each instance of the classes.
2. Custom Comment header line
In addition to the Version header line we can also add a Comment header line. This is done by setting the AsciiCommentHeader property.
C# example
PGPLib pgp = new PGPLib(); pgp.AsciiCommentHeader = "This is a test"; |
VB.NET example
Dim pgp As New PGPLib() pgp.AsciiCommentHeader = "This is a test" |
After setting the AsciiCommentHeader property on subsequent method calls the ASCII armored output will be:
-----BEGIN PGP MESSAGE-----
Version: xxx
Comment: This is a test
As of version 1.9.4.21 there is a support for multiple Comment lines as well in an additional AsciiCommentHeaders property of PGPLib, KeyStore. Here is how to add two Comment lines:
PGPLib pgp = new PGPLib(); pgp.AsciiCommentHeaders = new string[] {"This is a test1", "This is a test2"}; |
This will produce output like:
-----BEGIN PGP MESSAGE-----
Version: xxx
Comment: This is a test1
Comment: This is a test2
Summary
In this chapter we have discussed the customization of the Version header line in ASCII armored OpenPGP output produced by DidiSoft OpenPGP Library for .NET.
If you are not familiar how to create OpenPGP archives with the library, you can jump to the chapters that demonstrate OpenPGP encrypting, signing, clear text signing, signing and encrypting and detached signing.
List of properties used
PGPLib.AsciiVersionHeader | can be used for customization of the Version: xxx header line in ASCII armored output |
PGPLib.AsciiCommentHeader | can be used for customization of the Comment: xxx header line in ASCII armored output |
Properties with the same name are available in the classes KeyStore, KeyPairInformaton and RevocationLib.