OpenPGP Code Example: Set the PGP Version header


When signing or encrypting the resulting PGP message will include a "Version" header. By default this is set by the component and results in messages like:

-----BEGIN PGP MESSAGE-----
Version: IPWorks OpenPGP 2020

yMC1ATXKTUhaAQAA4OdPhppMG2SluWgSdTAlC9NGEFGGYjELKn8mPFSsnhluTKGD
lDsElhQ2pxQkQTkmG1kHCwKHFSZqYIqBEVQgRRmRBZHzrejQ+ft2CCgAifAxLW/8
YpcHESaBgDhno2lUEKSrNOj0kDLwV4YGEEgAU4B8EQCHJb72j6ZCuJQKm4fQKuXe
vf3gsr6B+3/wrA08T/dcdrocsfFkmX9+LHi9lISrIu3MPQ6XmLKzWjq62JyB+In6
V+vy3ETUeGHtM/5Ufvl+LjOpqQq/c/o0W00kHQ78/sSuY1B0K6mNEsPC6DxLsBXi
f3ZvUDZvmnxk8q0Iq/GohAHryKo+T5HTF2El5mi/keAUhgBvwpmpBeNhhgisUUD4
oD2znja/c0w+LX8zo3BX2h+8u2iUnv/Hp3mb3TxcBFXxVbrY+7ZoJjt5XD4seSi2
kSS73e+1/QlpdXoNkl0zi7C+wB+BxaYwgjE5/lG7ndsVdcxOfTh4Bg==
=9b/T
-----END PGP MESSAGE-----

The component allows for any user defined value to be set. This let's you customize the PGP message to identify your application as the originator. To specify your own value simply set the "VersionHeader" configuration setting like so:

//C# Key key = new Key("C:\\MyKeyring", "myuser@mail.com"); key.Passphrase = "password"; pgp.Keys.Add(key); pgp.InputMessage = "hello world"; pgp.Config("VersionHeader=My Application"); pgp.ASCIIArmor = true; pgp.Sign(); String encryptedMsg = pgp.OutputMessage;

This will result in a message like:

-----BEGIN PGP MESSAGE-----
Version: My Application

yMCyATXKQUhaAQAA0P9/1nLwLaEOIR+UrIh0QgexrxSjg3QwNjtkaJ80C7HfxCQ6
FSFFzCGVHqICcQxFMQix1LTWMHWrJIsioZWbGoGgQmJRUjk67PxeEC4DINDD+lK1
KzQ7wEOyDBAWjQXFEI6rqBOqMVwe+CEhACAEVJRDrwK8JVb/79ajNyXFmeZ9iNU/
yxWM/vmlTeW8W/5QmZqKxsgMhLi/xvcundDyQubftCJQFFlQJxPhtsGS7J4rO11K
opGPL3QTTXqvbDSxufVwC8YY0aXjOt5Ow20LRrwLXiXqeE9zfZCFDRO0pJkk+Ey5
WRnK8/Lou5+nx8qo7/JTFz65aGtOdthr7hd2ozHNwTf/V2Ste2AqLmIO/x5vM1vF
KWzDLsh9UBaQTnlgfn1Qv+yu8zVpMu7eCweL8nm1nSN1GOkP5zqnT2TgaGtJLm46
0urh94gphrA6Uwhj7O8Cvf42FKnctCHebRKEumQGNPGIXWv+AQ==
=yHVX
-----END PGP MESSAGE-----

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.