OpenPGP signs and encrypts a String message in one pass, backward compatible with PGP 6.5 and below

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

Syntax

C#
public string SignAndEncryptStringV3(
	string inputString,
	FileInfo privateKeyFile,
	string password,
	FileInfo publicKeyFile
)
Visual Basic
Public Function SignAndEncryptStringV3 ( _
	inputString As String, _
	privateKeyFile As FileInfo, _
	password As String, _
	publicKeyFile As FileInfo _
) As String
Visual C++
public:
String^ SignAndEncryptStringV3(
	String^ inputString, 
	FileInfo^ privateKeyFile, 
	String^ password, 
	FileInfo^ publicKeyFile
)

Parameters

inputString
Type: System..::..String
Message to be encrypted and 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

Return Value

the input message OpenPGP signed and encrypted

Remarks

* (Note that this is not the same as first encrypt and then sign, 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 OpenPGP sign and encrypt message and afterwards decrypt and verify it.
CopyC#
using DidiSoft.Pgp;
using System;
using System.IO;

public class Demo
{
    public void SignAndEncryptDemoV3()
    {
        FileInfo PrivateKey = new FileInfo(@"c:\private_key.asc");    
        String Password = "pass123";

     // Create an instance of the library
        PGPLib pgp = new PGPLib();

        string inputString = "stringToSign"; 

     // sign and encrypt compatible with PGP 6.5 and below
        String pgpString = pgp.SignAndEncryptStringV3(inputString, PrivateKey, Password, PublicKey);

        String outputString;
        bool verified = pgp.DecryptAndVerifyString(pgpString, PrivateKey, Password, PublicKey, out outputString);
    }
}
CopyVB.NET
Imports DidiSoft.Pgp
Imports System
Imports System.IO

Public Class Demo
    Public Sub SignAndEncryptDemoV3()
        Dim PrivateKey As New FileInfo("c:\private_key.asc")
        Dim Password As String = "pass123"

     ' Create an instance of the library
        Dim pgp As New PGPLib()

        Dim inputString As String = "stringToSign"

     ' sign and encrypt compatible with PGP 6.5 and below
        Dim pgpString As String = pgp.SignAndEncryptStringV3(inputString, PrivateKey, Password, PublicKey)

        Dim outputString As String
        Dim verified As Boolean = pgp.DecryptAndVerifyString(pgpString, PrivateKey, Password, PublicKey, outputString)
    End Sub
End Class

Exceptions

ExceptionCondition
DidiSoft.Pgp..::..PGPExceptionif an OpenPGP related error has occurred
System.IO..::..IOExceptionif a problem has occurred reading public key file or private key file
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