Decrypts and verifies a PGP encrypted and signed file

Namespace: DidiSoft.Pgp
Assembly: DidiSoft.Pgp (in DidiSoft.Pgp.dll) Version: 1.7.3.35547

Syntax

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

Parameters

encryptedFileName
Type: System..::..String
File name to be decrypted (absolute or relative path)
keyStore
Type: DidiSoft.Pgp..::..KeyStore
Key store instance containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword
Type: System..::..String
Private key password
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 signatures format (used by PGP 2.6 systems).

Examples

CopyC#
 using System;
 using DidiSoft.Pgp;

 public classKeyStoreDecryptAndVerifyFile
 {
 public static void Demo()
{
         KeyStore keyStore = new KeyStore(@"DataFiles\key.store", "password");        
          PGPLib pgp = new PGPLib();    

          bool validSigning = pgp.DecryptAndVerifyFile(@"DataFiles\OUTPUT.pgp", 
                                                      keyStore, 
                                                      "private key password", 
                                                      @"DataFiles\OUTPUT.txt");
          Console.WriteLine("Signature is valid: " + validSigning);

 } 
}
CopyVB.NET
Imports System
Imports DidiSoft.Pgp

Public ClassKeyStoreDecryptAndVerifyFile
 Public Shared Sub Demo()
         Dim keyStore As New KeyStore("DataFiles\key.store", "password")
         Dim pgp As new PGPLib()

         Dim validSigning As Boolean = pgp.DecryptAndVerifyFile("DataFiles\OUTPUT.pgp", _
                                                             keyStore, _
                                                             "private key password", _
                                                             "DataFiles\OUTPUT.txt")
         Console.WriteLine("Signature is valid: " + validSigning)
 End Sub
End Class

Exceptions

ExceptionCondition
DidiSoft.Pgp..::..PGPExceptionif an OpenPGP related error has occurred
System.IO..::..IOExceptionif a problem has occurred reading input file
DidiSoft.Pgp.Exceptions..::..WrongPasswordExceptionIf the password for the decryption key is incorrect
NonPGPDataExceptionif the input data is not a valid OpenPGP encrypted message

See Also