OpenPGP Signs and encrypts given file with supplied public and private key

Namespace:  DidiSoft
Assembly:  PGPLib (in PGPLib.dll) Version: 1.6.3.19546

Syntax

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

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
armor
Type: System..::.Boolean
if true, output file is in ASCII armored format
withIntegrityCheck
Type: System..::.Boolean
Should integrity check information be added to the file.

Remarks

* Note that this is not the same as first encrypt and then sign a file, because in that case a double compressing 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.
CopyC#
   using System;
   using System.IO;
   using DidiSoft;

public class SignAndEncrypt
{
 public void Demo()
 {
   PGPLib pgp = new PGPLib();

   bool armor = false;
   bool withIntegrityCheck = false;
   FileInfo inputFile = new FileInfo(@"DataFiles\INPUT.txt");
   FileInfo privateKeyFile = new FileInfo(@"DataFiles\private.key");
   FileInfo publicKeyFile = new FileInfo(@"DataFiles\public.key");
   FileInfo outputFile = new FileInfo(@"DataFiles\OUTPUTse.pgp");
   pgp.SignAndEncryptFile(inputFile,
                               privateKeyFile, 
                               "changeit",
                               publicKeyFile,
                               outputFile, 
                               armor,
                               withIntegrityCheck);            

}
CopyVB.NET
VB.NET
<hr></hr>
   Imports System
   Imports DidiSoft

   Public Class SignAndEncrypt
       Public Sub Demo()
           Dim pgp As New PGPLib()

           Dim armor As Boolean = False
           Dim withIntegrityCheck As Boolean = False
           Dim inputFile As FileInfo = new FileInfo("DataFiles\INPUT.txt")
           Dim privateKeyFile As FileInfo = new FileInfo("DataFiles\private.key")
           Dim publicKeyFile As FileInfo = new FileInfo("DataFiles\public.key")
           Dim outputFile As FileInfo = new FileInfo("DataFiles\OUTPUTse.pgp")
            pgp.SignAndEncryptFile(inputFile, _
                               privateKeyFile, _
                               "changeit", _
                               publicKeyFile, _
                               outputFile, _
                               armor, _
                               withIntegrityCheck)
       End Sub
   End Class

Exceptions

ExceptionCondition
PgpExceptionif an error has occured
System.IO..::.IOExceptionif a problem has reading input file or private key file

See Also