Decrypts an PGP encrypted file using Private key file.

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

Syntax

C#
public string DecryptFile(
	FileInfo encryptedFile,
	FileInfo privateKeyFile,
	string privateKeyPassword,
	FileInfo outputFile
)
Visual Basic
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 occurred.

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.Pgp;

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.Pgp

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
System.IO..::..IOExceptionI/O error
DidiSoft.Pgp..::..PGPExceptionGeneral OpenPGP error
DidiSoft.Pgp.Exceptions..::..WrongPrivateKeyExceptionIf the supplied private key cannot be used to decrypt this message
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