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
| Visual Basic (Declaration) |
|---|
Public Function DecryptFile ( _
encryptedFileName As String, _
privateKeyStream As Stream, _
privateKeyPassword As String, _
outputFileName As String _
) As String |
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()
{
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";
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()
Dim pgp As New PGPLib()
Dim privateKeyStream As Stream = Nothing
Try
privateKeyStream = New FileStream("c:\private_key.asc", FileMode.Open)
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
| Exception | Condition |
|---|
| PgpException | if an error has occured |
| System.IO..::.IOException | if a problem has occured reading input file or private key file |
See Also