OpenPGP Signs and encrypts given file with public and private key located in a KeyStore

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

Syntax

C#
public void SignAndEncryptFile(
	string inputFileName,
	KeyStore keyStore,
	string privateKeyUserId,
	string privateKeyPassword,
	string signKeyUserId,
	string outputFileName,
	bool armor,
	bool withIntegrityCheck
)
Visual Basic (Declaration)
Public Sub SignAndEncryptFile ( _
	inputFileName As String, _
	keyStore As KeyStore, _
	privateKeyUserId As String, _
	privateKeyPassword As String, _
	signKeyUserId As String, _
	outputFileName As String, _
	armor As Boolean, _
	withIntegrityCheck As Boolean _
)
Visual C++
public:
void SignAndEncryptFile(
	String^ inputFileName, 
	KeyStore^ keyStore, 
	String^ privateKeyUserId, 
	String^ privateKeyPassword, 
	String^ signKeyUserId, 
	String^ outputFileName, 
	bool armor, 
	bool withIntegrityCheck
)

Parameters

inputFileName
Type: System..::.String
File Name to be PGP Signed (absolute or relative path)
keyStore
Type: DidiSoft..::.KeyStore
KeyStore instance
privateKeyUserId
Type: System..::.String
User Id of the form "name (comment) <email address>"
The first Private Key with this User Id located in keyStore is used for excryption.
privateKeyPassword
Type: System..::.String
Private key password
signKeyUserId
Type: System..::.String
User Id of the form "name (comment) <email address>"
The first Public Key with this User Id located in keyStore is used for signing.
outputFileName
Type: System..::.String
File name of the PGP Signed file (absolute or relative path)
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.)

Examples

This sample shows how to sign and encrypt a file in one pass.
CopyC#
using System;
using DidiSoft;

public class KeyStoreSignAndeEncryptFile
{
    public static void Demo()
    {
     KeyStore keyStore = new KeyStore(@"DataFiles\key.store", "changeit");        
     PGPLib pgp = new PGPLib();

     bool asciiArmor = true;
     bool withIntegrityCheck = true;

     String signUserId = "My Company contact@mycompany.com";
     String privateKeyPassword = "changeit"; 
     String encUserId = "Receiver Company support@didisoft.com";

     pgp.SignAndEncryptFile("INPUT.txt",
                              keyStore,
                              signUserId,
                              privateKeyPassword,
                              encUserId,
                              "OUTPUT.pgp",                                  
                              asciiArmor, 
                              withIntegrityCheck);            
    }
}
CopyVB.NET
Imports System
Imports DidiSoft

Public Class KeyStoreSignAndEncryptFile
    Public Shared Sub Demo()
        Dim keyStore As New KeyStore("DataFiles\key.store", "changeit")
        Dim pgp As New PGPLib()

        Dim asciiArmor As Boolean = True
        Dim withIntegrityCheck As Boolean = True

        Dim signUserId As String = "My Company contact@mycompany.com"
        Dim privateKeyPassword As String = "changeit"
        Dim encUserId As String = "Receiver Company support@didisoft.com"

        pgp.SignAndEncryptFile("DataFiles\INPUT.txt", _ 
                                                  keyStore, signUserId, _ 
                                                  privateKeyPassword, _ 
                                                  encUserId, _ 
                                                 "DataFiles\OUTPUT.pgp", _ 
                                                 asciiArmor, 
                                                 withIntegrityCheck)
    End Sub
End Class

Exceptions

ExceptionCondition
PgpExceptionif an error has occured

See Also