NET PGP Library
DecryptFileAsync(String,String,String,String) Method
Example 



KellermanSoftware.NetPgpLibrary Namespace > PgpEncryptorDecryptor Class : DecryptFileAsync(String,String,String,String) Method
The file to decrypt
The destination path and filename for the decrypted file
The private key file
The password for the key file
Decrypt a file asynchronously
Syntax
'Declaration
 
<AsyncStateMachineAttribute(KellermanSoftware.NetPgpLibrary.PgpEncryptorDecryptor/d__15)> 
<DebuggerStepThroughAttribute()> 
Public Function DecryptFileAsync( _ 
   ByVal sourceFilePath As String, _ 
   ByVal decryptedFilePath As String, _ 
   ByVal privateKeyFile As String, _ 
   ByVal password As String _ 
) As Task
'Usage
 
Dim instance As PgpEncryptorDecryptor
Dim sourceFilePath As String
Dim decryptedFilePath As String
Dim privateKeyFile As String
Dim password As String
Dim value As Task
 
value = instance.DecryptFileAsync(sourceFilePath, decryptedFilePath, privateKeyFile, password)
[AsyncStateMachine(KellermanSoftware.NetPgpLibrary.PgpEncryptorDecryptor/d__15)] 
[DebuggerStepThrough()] 
public Task DecryptFileAsync( 
   string sourceFilePath, 
   string decryptedFilePath, 
   string privateKeyFile, 
   string password 
)
[AsyncStateMachine(KellermanSoftware.NetPgpLibrary.PgpEncryptorDecryptor/d__15)] 
[DebuggerStepThrough()] 
public: 
Task^ DecryptFileAsync( 
   String^ sourceFilePath, 
   String^ decryptedFilePath, 
   String^ privateKeyFile, 
   String^ password 
) 

Parameters

sourceFilePath
The file to decrypt
decryptedFilePath
The destination path and filename for the decrypted file
privateKeyFile
The private key file
password
The password for the key file
Example
PgpEncryptorDecryptor pgpEncryptorDecryptor = new PgpEncryptorDecryptor(); //Trial Mode
//PgpEncryptorDecryptor pgpEncryptorDecryptor = new PgpEncryptorDecryptor("place user name here", "place license key here"); //License Mode
 
// we need to generate the keys first if we haven't got them already
string username = "username";
string password = "password";
string directoryForKeys = Directory.GetCurrentDirectory();
string publicKeyFilePath = Path.Combine(directoryForKeys, "public.asc");
string privateKeyFilePath = Path.Combine(directoryForKeys, "private.asc");
 
pgpEncryptorDecryptor.GenerateKeyPairFiles(username, password, publicKeyFilePath, privateKeyFilePath);
 
//Create a test file
string directoryForFiles = Directory.GetCurrentDirectory();
string inputFilePath = Path.Combine(directoryForFiles, "input.txt");
File.WriteAllText(inputFilePath, "This is a test");
 
string encryptedFilePath = Path.Combine(directoryForFiles, "encrypted.pgp");
bool armor = true;
 
await pgpEncryptorDecryptor.EncryptFileAsync(inputFilePath, encryptedFilePath, publicKeyFilePath, armor);
 
// decrypt file         
string decryptedFilePath = Path.Combine(directoryForFiles, "decrypted.txt");
await pgpEncryptorDecryptor.DecryptFileAsync(encryptedFilePath, decryptedFilePath, privateKeyFilePath, "password");
Dim pgpEncryptorDecryptor As New PgpEncryptorDecryptor() 'Trial Mode
'Dim pgpEncryptorDecryptorLicensed As New PgpEncryptorDecryptor("place user name here", "place license key here") //License Mode
 
' we need to generate the keys first if we haven't got them already
Dim username As String = "username"
Dim password As String = "password"
Dim directoryForKeys As String = Directory.GetCurrentDirectory()
Dim publicKeyFilePath As String = Path.Combine(directoryForKeys, "public.asc")
Dim privateKeyFilePath As String = Path.Combine(directoryForKeys, "private.asc")
 
pgpEncryptorDecryptor.GenerateKeyPairFiles(username, password, publicKeyFilePath, privateKeyFilePath)
 
'Create a test file
Dim directoryForFiles As String = Directory.GetCurrentDirectory()
Dim inputFilePath As String = Path.Combine(directoryForFiles, "input.txt")
File.WriteAllText(inputFilePath, "This is a test")
 
Dim encryptedFilePath As String = Path.Combine(directoryForFiles, "encrypted.pgp")
Dim armor As Boolean = True
 
Await pgpEncryptorDecryptor.EncryptFileAsync(inputFilePath, encryptedFilePath, publicKeyFilePath, armor)
 
' decrypt file         
Dim decryptedFilePath As String = Path.Combine(directoryForFiles, "decrypted.txt")
Await pgpEncryptorDecryptor.DecryptFileAsync(encryptedFilePath, decryptedFilePath, privateKeyFilePath, "password")
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PgpEncryptorDecryptor Class
PgpEncryptorDecryptor Members