Decrypts an OpenPGP encrypted file with a private key supplied as an input stream.

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

Syntax

C#
public string DecryptFile(
	string encryptedFileName,
	Stream privateKeyStream,
	string privateKeyPassword,
	string outputFileName
)
Visual Basic (Declaration)
Public Function DecryptFile ( _
	encryptedFileName As String, _
	privateKeyStream As Stream, _
	privateKeyPassword As String, _
	outputFileName As String _
) As String
Visual C++
public:
String^ DecryptFile(
	String^ encryptedFileName, 
	Stream^ privateKeyStream, 
	String^ privateKeyPassword, 
	String^ outputFileName
)

Parameters

encryptedFileName
Type: System..::.String
File name to be decrypted (absolute or relative path)
privateKeyStream
Type: System.IO..::.Stream
Private Key input stream
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

File name of the decrypted file. null if and error has occured.

Examples

This example shows how to decrypt an OpenPGP encrypted file with a decryption private key and the key password.
CopyC#
using System;
using System.IO;
using DidiSoft;

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

 Stream privateKeyStream = null;
 try {
   privateKeyStream = new FileStream(@"c:\private_key.asc", FileMode.Open);
      string inputFileLocation = @"c:\INPUT.pgp";
      string privateKeyPassword = "key password";
      string decryptedOutput = @"c:\OUTPUT.txt";

      // decrypt and obtain the original file name
      string originalFileName = 
        pgp.DecryptFile(inputFileLocation,
                      privateKeyStream,
                      privateKeyPassword,
                      decryptedOutput);        
     } finally {
       privateKeyStream.Close();
     }
 }
}
CopyVB.NET
Imports System
Imports System.IO
Imports DidiSoft

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

  Dim privateKeyStream As Stream = Nothing
  Try 

   privateKeyStream = New FileStream("c:\private_key.asc", FileMode.Open)

      ' decrypt and obtain the original file name
      Dim originalFileName As String
      originalFileName = _
        pgp.DecryptFile("c:\INPUT.pgp", _
                    privateKeyStream, _
                    "key password", _
                    "c:\OUTPUT.txt")
     Finally
           privateKeyStream.Close()
    End Try
 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