Decrypts a PGP encrypted stream 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[] DecryptStreamInFolder(
	Stream encryptedPGPStream,
	KeyStore keyStore,
	string privateKeyPassword,
	string outputFolderName
)
Visual Basic
Public Function DecryptStreamInFolder ( _
	encryptedPGPStream As Stream, _
	keyStore As KeyStore, _
	privateKeyPassword As String, _
	outputFolderName As String _
) As String()
Visual C++
public:
array<String^>^ DecryptStreamInFolder(
	Stream^ encryptedPGPStream, 
	KeyStore^ keyStore, 
	String^ privateKeyPassword, 
	String^ outputFolderName
)

Parameters

encryptedPGPStream
Type: System.IO..::..Stream
PGP encrypted stream to be decrypted
keyStore
Type: DidiSoft.Pgp..::..KeyStore
KeyStore instance containing the private decryption key
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)

Remarks

The multiple files OpenPGP archives are supported by PGP Desktop (tm) 9+ and compatible software.

Examples

CopyC#
using System;
using System.IO;
using DidiSoft.Pgp;

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

   // initialize theKeyStore
  KeyStore keysStore = new KeyStore("c:\pgp.keystore"); 

  FileInfo inputFile = new FileInfo(@"c:\INPUT.pgp");
  string privateKeyPassword = "decryption key password";
  string outputFolder = @"c:\Output";

  // decrypt and obtain the original file name(s)
  string[] decryptedFileNames = 
  pgp.DecryptStreamTo(inputFile.OpenRead(),
                         keysStore,
                         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 System.IO
Imports DidiSoft.Pgp

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

 ' initialize theKeyStore
 Dim keysStore As New KeyStore("c:\pgp.keystore") 

    Dim inputFile As New FileInfo("c:\INPUT.pgp")
    Dim outputFolder As String = "c:\Output"

    ' decrypt and obtain the original file name
    Dim decryptedFileNames As String() = _
      pgp.DecryptStreamTo(inputFile.OpenRead(), _
                    keysStore, _
                    "decryption 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