NET PGP Library
EncryptFileAsync(String,String,String,Boolean) Method
Example 



View with Navigation Tools
KellermanSoftware.NetPgpLibrary Namespace > PgpEncryptorDecryptor Class : EncryptFileAsync(String,String,String,Boolean) Method
The file to encrpt
The destination path and filename for the encrypted file
The public key file
Use ASCII Armor
Encrypt a file asynchronously
Syntax
'Declaration
 
<AsyncStateMachineAttribute(KellermanSoftware.NetPgpLibrary.PgpEncryptorDecryptor/d__14)> 
<DebuggerStepThroughAttribute()> 
Public Function EncryptFileAsync( _ 
   ByVal sourceFilePath As String, _ 
   ByVal encryptedFilePath As String, _ 
   ByVal publicKeyFile As String, _ 
   ByVal armor As Boolean _ 
) As Task
 
'Usage
 
Dim instance As PgpEncryptorDecryptor
Dim sourceFilePath As String
Dim encryptedFilePath As String
Dim publicKeyFile As String
Dim armor As Boolean
Dim value As Task
 
value = instance.EncryptFileAsync(sourceFilePath, encryptedFilePath, publicKeyFile, armor)

Parameters

sourceFilePath
The file to encrpt
encryptedFilePath
The destination path and filename for the encrypted file
publicKeyFile
The public key file
armor
Use ASCII Armor
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);
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