OpenPGP Signs and encrypts given file backward compatibile with PGP 6.5 and below

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

Syntax

C#
public void SignAndEncryptFileV3(
	FileInfo inputFile,
	FileInfo privateKeyFile,
	string password,
	FileInfo publicKeyFile,
	FileInfo outputFile,
	bool asciiArmor
)
Visual Basic
Public Sub SignAndEncryptFileV3 ( _
	inputFile As FileInfo, _
	privateKeyFile As FileInfo, _
	password As String, _
	publicKeyFile As FileInfo, _
	outputFile As FileInfo, _
	asciiArmor As Boolean _
)
Visual C++
public:
void SignAndEncryptFileV3(
	FileInfo^ inputFile, 
	FileInfo^ privateKeyFile, 
	String^ password, 
	FileInfo^ publicKeyFile, 
	FileInfo^ outputFile, 
	bool asciiArmor
)

Parameters

inputFile
Type: System.IO..::..FileInfo
File to be PGP signed
privateKeyFile
Type: System.IO..::..FileInfo
Private Key file, used for signing
password
Type: System..::..String
Private key password
publicKeyFile
Type: System.IO..::..FileInfo
Public key file, used for encryption
outputFile
Type: System.IO..::..FileInfo
Output file, PGP signed
asciiArmor
Type: System..::..Boolean
if true, output file is in ASCII armored format

Remarks

* Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.
Compression algorithm used is the one specified through Compression
Symmetric cipher algorithm used is the one specified through Cypher

Examples

This sample shows how to sign and encrypt a file in one pass backward compatibile with PGP 6.5 and below
CopyC#
   using System;
   using System.IO;
   using DidiSoft.Pgp;

public class SignAndEncryptV3
{
 public void Demo()
 {
   // Create an instance of the library
   PGPLib pgp = new PGPLib();

   // Should output be ASCII (true) or binary (false)  
   bool asciiArmor = false;

   FileInfo inputFile = new FileInfo(@"DataFiles\INPUT.txt");

   // Signing private key (usually our own private key)  
   FileInfo privateKeyFile = new FileInfo(@"DataFiles\private.key");
   // Public key used for encryption (usually the public key of the recipient)
   FileInfo publicKeyFile = new FileInfo(@"DataFiles\public.key");
   // Encrypted output
   FileInfo outputFile = new FileInfo(@"DataFiles\OUTPUTse.pgp");

   pgp.SignAndEncryptFileV3(inputFile,
                               privateKeyFile, 
                               "password",
                               publicKeyFile,
                               outputFile, 
                               asciiArmor);            
}
CopyVB.NET
VB.NET
<hr></hr>
   Imports System
   Imports DidiSoft.Pgp

   Public Class SignAndEncryptV3
       Public Sub Demo()
           ' Create an instance of the library
           Dim pgp As New PGPLib()

         ' Should output be ASCII (true) or binary (false)
           Dim asciiArmor As Boolean = False

           Dim inputFile As FileInfo = new FileInfo("DataFiles\INPUT.txt")

         ' Signing private key (usually our own private key)
           Dim privateKeyFile As FileInfo = new FileInfo("DataFiles\private.key")
           ' Public key used for encryption (usually the public key of the recipient)
           Dim publicKeyFile As FileInfo = new FileInfo("DataFiles\public.key")
           ' Encrypted output
           Dim outputFile As FileInfo = new FileInfo("DataFiles\OUTPUTse.pgp")

            pgp.SignAndEncryptFileV3(inputFile, _
                               privateKeyFile, _
                               "password", _
                               publicKeyFile, _
                               outputFile, _
                               asciiArmor)
       End Sub
   End Class

Exceptions

ExceptionCondition
DidiSoft.Pgp..::..PGPExceptionif an OpenPGP related error has occurred
System.IO..::..IOExceptionI/O error
DidiSoft.Pgp.Exceptions..::..WrongPasswordExceptionif the supplied password for the private key is incorrect
DidiSoft.Pgp.Exceptions..::..WrongPrivateKeyExceptionif the supplied private key is not suitable for signing

See Also