OpenPGP Signs and encrypts given file with supplied public and private key
Namespace: DidiSoft.PgpAssembly: DidiSoft.Pgp (in DidiSoft.Pgp.dll) Version: 1.7.3.35547
Syntax
| C# |
|---|
public void SignAndEncryptFile( FileInfo inputFile, FileInfo privateKeyFile, string password, FileInfo publicKeyFile, FileInfo outputFile, bool asciiArmor, bool withIntegrityCheck ) |
| Visual Basic |
|---|
Public Sub SignAndEncryptFile ( _ inputFile As FileInfo, _ privateKeyFile As FileInfo, _ password As String, _ publicKeyFile As FileInfo, _ outputFile As FileInfo, _ asciiArmor As Boolean, _ withIntegrityCheck As Boolean _ ) |
| Visual C++ |
|---|
public: void SignAndEncryptFile( FileInfo^ inputFile, FileInfo^ privateKeyFile, String^ password, FileInfo^ publicKeyFile, FileInfo^ outputFile, bool asciiArmor, 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
- asciiArmor
- 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 compression is performed.
Compression algorithm used is the one specified through Compression
Symmetric cipher algorithm used is the one specified through Cypher
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#
CopyVB.NET
using System; using System.IO; using DidiSoft.Pgp; public class SignAndEncrypt { public void Demo() { // Create an instance of the library PGPLib pgp = new PGPLib(); // Should output be ASCII (true) or binary (false) bool asciiArmor = false; // If true additional integrity check information will be appended bool withIntegrityCheck = 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.SignAndEncryptFile(inputFile, privateKeyFile, "password", publicKeyFile, outputFile, asciiArmor, withIntegrityCheck); }
VB.NET <hr></hr> Imports System Imports DidiSoft.Pgp Public Class SignAndEncrypt 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 ' If true additional integrity check information will be appended Dim withIntegrityCheck 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.SignAndEncryptFile(inputFile, _ privateKeyFile, _ "password", _ publicKeyFile, _ outputFile, _ asciiArmor, _ withIntegrityCheck) End Sub End Class
Exceptions
| Exception | Condition |
|---|---|
| DidiSoft.Pgp..::..PGPException | if an OpenPGP related error has occurred |
| System.IO..::..IOException | I/O error |
| DidiSoft.Pgp.Exceptions..::..WrongPasswordException | if the supplied password for the private key is incorrect |
| DidiSoft.Pgp.Exceptions..::..WrongPrivateKeyException | if the supplied private key is not suitable for signing |