DidiSoft OpenPGP Library for .NET can encrypt a file with both the public key of the recipient and additional password. In this case if for some reason the corresponding private key of the recipient has been lost the encrypted file can still be decrypted with the additional password.
The encryption with a password is also known as ‘password based encryption‘ or PBE for short.
The example below demonstrates this in practice:
C#
using System.IO; using DidiSoft.Pgp; class EncryptFileWithPassword { public void Demo() { String additionalDecryptionPassword = "extra password"; PGPLib pgp = new PGPLib(); bool asciiArmor = false; bool withIntegrityCheck = false; pgp.EncryptFilePBE(@"DataFiles\INPUT.txt", @"DataFiles\public.key", additionalDecryptionPassword, @"DataFiles\OUTPUT.pgp", asciiArmor, withIntegrityCheck); } } |
VB.NET
Imports System Imports DidiSoft.Pgp Class EncryptFileWithPassword Public Sub Demo() Dim additionalDecryptionPassword As String = "extra password" Dim pgp As New PGPLib() Dim asciiArmor As Boolean = False Dim withIntegrityCheck As Boolean = False pgp.EncryptFilePBE("DataFiles\INPUT.txt", _ "DataFiles\public.key", _ additionalDecryptionPassword, _ "DataFiles\OUTPUT.pgp", _ asciiArmor, _ withIntegrityCheck) End Sub End Class |
An example that shows how to decrypt an OpenPGP password encrypted file can be found at:
https://www.didisoft.com/net-openpgp/examples/decrypt-file/#DecryptPBE