Decrypts a PGP encrypted file that may contain multiple files to a specified directory.

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

Syntax

C#
public string[] DecryptFileInFolder(
	string encryptedFileName,
	string privateKeyFileName,
	string privateKeyPassword,
	string outputFolderName
)
Visual Basic
Public Function DecryptFileInFolder ( _
	encryptedFileName As String, _
	privateKeyFileName As String, _
	privateKeyPassword As String, _
	outputFolderName As String _
) As String()
Visual C++
public:
array<String^>^ DecryptFileInFolder(
	String^ encryptedFileName, 
	String^ privateKeyFileName, 
	String^ privateKeyPassword, 
	String^ outputFolderName
)

Parameters

encryptedFileName
Type: System..::..String
PGP encrypted stream to be decrypted
privateKeyFileName
Type: System..::..String
Private Key input stream
privateKeyPassword
Type: System..::..String
Private key password
outputFolderName
Type: System..::..String
Folder where decrypted file(s) will be extracted (absolute or relative path).

Return Value

Array of file names of the decrypted file(s)

Examples

CopyC#
using System;
using DidiSoft.Pgp;

public class DecryptDemo
{
 public void Demo()
 {
    // initialize the library
    PGPLib pgp = new PGPLib();

    string inputFileLocation = @"c:\INPUT.pgp";
    string privateKeyLocation = @"c:\private_key.asc";
    string privateKeyPassword = "key password";
    string outputFolder = @"c:\Output";

    // decrypt and return array with full file paths 
    // of the extracted file(s)
    string[] decryptedFileNames = 
      pgp.DecryptFileTo(inputFileLocation,
                      privateKeyLocation,
                      privateKeyPassword,
                      outputFolder);

     // print the full path of the decrypted file(s)
     foreach (string filename in decryptedFileNames)
     {
        System.Console.WriteLine(filename);
     }
 }
}
CopyVB.NET
Imports System
Imports DidiSoft.Pgp

Public Class DecryptDemo
Public Sub Demo()
    ' create an instance of the library
    Dim pgp As New PGPLib()

    Dim inputFileLocation As String = "c:\INPUT.pgp"
    Dim privateKeyLocation As String = "c:\private_key.asc"
    Dim outputFolder As String = "c:\Output"

    ' decrypt and return array with full file paths
    ' of the exytracted file(s)
    Dim decryptedFileNames As String() = _
      pgp.DecryptFileTo(inputFileLocation, _
                    privateKeyLocation, _
                    "key password", _
                    outputFolder)

  ' print the full path of the decrypted file(s)
  For Each filename As String In decryptedFileNames
      System.Console.WriteLine(filename)
  Next   
 End Sub
End Class

Exceptions

ExceptionCondition
System.IO..::..IOExceptionI/O error
DidiSoft.Pgp..::..PGPExceptionGeneral OpenPGP error
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