Decrypts a PGP encrypted file using Private key file.

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

Syntax

C#
public string DecryptFile(
	FileInfo encryptedFile,
	FileInfo privateKeyFile,
	string privateKeyPassword,
	FileInfo outputFile
)
Visual Basic (Declaration)
Public Function DecryptFile ( _
	encryptedFile As FileInfo, _
	privateKeyFile As FileInfo, _
	privateKeyPassword As String, _
	outputFile As FileInfo _
) As String
Visual C++
public:
String^ DecryptFile(
	FileInfo^ encryptedFile, 
	FileInfo^ privateKeyFile, 
	String^ privateKeyPassword, 
	FileInfo^ outputFile
)

Parameters

encryptedFile
Type: System.IO..::.FileInfo
File to be decrypted
privateKeyFile
Type: System.IO..::.FileInfo
Private Key file
privateKeyPassword
Type: System..::.String
Private key password
outputFile
Type: System.IO..::.FileInfo
Output file (decrypted)

Return Value

File name of the decrypted file. null if an error had occured.

Examples

CopyC#
public void DecryptDemo() {
  PGPLib pgp = new PGPLib();
  FileInfo encryptedFile = new FileInfo(@"C:\Test\INPUT.pgp");
  FileInfo privateKeyFile = new FileInfo(@"C:\Test\private.key");
  FileInfo outputFile = new FileInfo(@"C:\Test\decrypted.txt");
  pgp.DecryptFile(encryptedFile, privateKeyFile, "pass123", outputFile);
}
CopyC#
using System;
using System.IO;
using DidiSoft;

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

    FileInfo inputFile = new FileInfo(@"c:\INPUT.pgp");
    FileInfo privateKeyLocation = new FileInfo(@"c:\private_key.asc");
    string privateKeyPassword = "key password";
    FileInfo decryptedOutput = new FileInfo(@"c:\OUTPUT.txt");

    // decrypt and obtain the original file name
    string originalFileName = 
      pgp.DecryptFile(inputFileLocation,
                      privateKeyLocation,
                      privateKeyPassword,
                      decryptedOutput);        
 }
}
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()

    ' decrypt and obtain the original file name
    Dim originalFileName As String
    originalFileName = 
      pgp.DecryptFile(New FileInfo("c:\INPUT.pgp"), _
                      New FileInfo("c:\private_key.asc"), _
                      "key password", _
                      New FileInfo("c:\OUTPUT.txt"))
 End Sub
End Class

Exceptions

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

See Also