Decrypts a 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(
	string encryptedFileName,
	string privateKeyFileName,
	string privateKeyPassword,
	string outputFileName
)
Visual Basic
Public Function DecryptFile ( _
	encryptedFileName As String, _
	privateKeyFileName As String, _
	privateKeyPassword As String, _
	outputFileName As String _
) As String
Visual C++
public:
String^ DecryptFile(
	String^ encryptedFileName, 
	String^ privateKeyFileName, 
	String^ privateKeyPassword, 
	String^ outputFileName
)

Parameters

encryptedFileName
Type: System..::..String
File name to be decrypted (absolute or relative path)
privateKeyFileName
Type: System..::..String
Private Key file name (absolute or relative path)
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 error occure.

Examples

This example shows how to decrypt an OpenPGP encrypted file with a decryption private key and the key password.
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 decryptedOutput = @"c:\OUTPUT.txt";

    // decrypt and obtain the original file name
    string originalFileName = 
      pgp.DecryptFile(inputFileLocation,
                      privateKeyLocation,
                      privateKeyPassword,
                      decryptedOutput);        
 }
}
CopyVB.NET
Imports System
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("c:\INPUT.pgp", _
                    "c:\private_key.asc", _
                    "key password", _
                    "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