Preferred hash function for pgp signatures in C# and VB.NET

Hashing is used in digital signatures. By default DidiSoft OpenPGP Library for .NET uses SHA1.

To set another hashing algorithm to be used for signing data, you have to change the default with the property Hash of a PGPLib class instance.

The possible values are listed in the DidiSoft.Pgp.HashAlgorithm enumeration:

HashAlgorithm.SHA1
HashAlgorithm.SHA256
HashAlgorithm.SHA384
HashAlgorithm.SHA512
HashAlgorithm.SHA224
HashAlgorithm.MD5
HashAlgorithm.MD2
HashAlgorithm.RIPEMD160

The change will have effect on subsequent calls to all Sign and SignAndEncrypt methods of the modified PGPLib class instance. For each new instance it has to be set explicitly again.

Example code

This example shows how to set the digital signature hashing algorithm to SHA-256:

C# example

PGPLib pgp = new PGPLib();
pgp.Hash = HashAlgorithm.SHA256;

VB.NET code

Dim pgp As New PGPLib()
pgp.Hash = HashAlgorithm.SHA256

Summary

This chapter discussed changing the hash function used in OpenPGP signatures created with the PGPLib class.
You may also be interested in how to change the default cipher and default compression algorithms.