Decrypts and verifies a PGP encrypted and signed file

Namespace:  DidiSoft
Assembly:  PGPLib (in PGPLib.dll) Version: 1.6.3.19546

Syntax

C#
public bool DecryptAndVerifyFile(
	string encryptedFileName,
	string privateKeyFileName,
	string privateKeyPassword,
	string publicKeyFile,
	string outputFileName
)
Visual Basic (Declaration)
Public Function DecryptAndVerifyFile ( _
	encryptedFileName As String, _
	privateKeyFileName As String, _
	privateKeyPassword As String, _
	publicKeyFile As String, _
	outputFileName As String _
) As Boolean
Visual C++
public:
bool DecryptAndVerifyFile(
	String^ encryptedFileName, 
	String^ privateKeyFileName, 
	String^ privateKeyPassword, 
	String^ publicKeyFile, 
	String^ outputFileName
)

Parameters

encryptedFileName
Type: System..::.String
File name to be decrypted (absolute or relative path)
privateKeyFileName
Type: System..::.String
Private Key input file (absolute or relative path)
privateKeyPassword
Type: System..::.String
Private key password
publicKeyFile
Type: System..::.String
Public Key file name (absolute or relative path)
outputFileName
Type: System..::.String
File name of the Output decrypted file (absolute or relative path). Optional parameter.
If empty the name stored in the PGP decrypted file is used.

Return Value

true if signature is valid, false if signature is invalid

Remarks

Supports OpenPGP version 3 format too (used by PGP 2.x systems).

Examples

CopyC#
using System;
using DidiSoft;

public class DecryptAndVerify
{
  public void Demo()
  {
    PGPLib pgp = new PGPLib();
    bool validSigning = pgp.DecryptAndVerifyFile(@"DataFiles\OUTPUTse.pgp",
                                                 @"DataFiles\private.key", 
                                                 "private key password",
                                                 @"DataFiles\public.key",
                                                 @"DataFiles\OUTPUT.txt");

    Console.WriteLine("Signature is valid: " + validSigning);      
  }
}
CopyVB.NET
Imports System
Imports DidiSoft

Public Class DecryptAndVerify
  Public Sub Demo()
    Dim pgp As New PGPLib()
    Dim validSigning As Boolean = pgp.DecryptAndVerifyFile("DataFiles\OUTPUT.pgp", _
                                            "DataFiles\private.key", _
                                            "private key password", _
                                            "DataFiles\public.key", _
                                            "DataFiles\OUTPUT.txt")

    Console.WriteLine("Signature is valid: " + validSigning)
  End Sub
End Class

Exceptions

ExceptionCondition
PgpExceptionif an error has occured
System.IO..::.IOExceptionif a problem has occured reading input file or private key file

See Also