Decrypts and verifies PGP encrypted and signed string message

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

Syntax

C#
public bool DecryptAndVerifyString(
	string inputString,
	FileInfo privateKeyFile,
	string privateKeyPassword,
	FileInfo publicKeyFile,
	out string outputString
)
Visual Basic
Public Function DecryptAndVerifyString ( _
	inputString As String, _
	privateKeyFile As FileInfo, _
	privateKeyPassword As String, _
	publicKeyFile As FileInfo, _
	<OutAttribute> ByRef outputString As String _
) As Boolean
Visual C++
public:
bool DecryptAndVerifyString(
	String^ inputString, 
	FileInfo^ privateKeyFile, 
	String^ privateKeyPassword, 
	FileInfo^ publicKeyFile, 
	[OutAttribute] String^% outputString
)

Parameters

inputString
Type: System..::..String
String message that is OpenPGP encrypted and optionaly signed
privateKeyFile
Type: System.IO..::..FileInfo
Private Key file, that will be used for decryption
privateKeyPassword
Type: System..::..String
Private key password
publicKeyFile
Type: System.IO..::..FileInfo
Public Key file, that will be used to verify the signature
outputString
Type: System..::..String%
Decrypted message.
Must be called with the out keyword in C#. In VB.NET is a normal ByRef invokation.

Return Value

true if signature is valid, false if signature is invalid

Remarks

Supports OpenPGP version 3 format too (used by PGP 2.x systems).

Examples

This sample shows how to decrypt and verify OpenPGP signed and encrypted string message.
CopyC#
using DidiSoft.Pgp;
using System;
using System.IO;

public class Demo
{
 public void DecryptAndVerifyDemo()
 {
     string pgpString = "...."; // the signed and encrypted message 

     // our private key used for decryption
     FileInfo PrivateKey = new FileInfo(@"c:\our_private_key.asc");    
     String Password = "pass123";

     // recipient public key used for verification of the signature
     FileInfo PublicKey = new FileInfo(@"c:\recipient_public_key.asc");

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

     // verify the validity of the signature and extract the encrypted string message
        string outputString = String.Empty;
        bool signatureIsValid = pgp.DecryptAndVerifyString(pgpString, 
                                                            PrivateKey, 
                                                            Password, 
                                                            PublicKey, 
                                                            outputString);
 }
}
CopyVB.NET
Imports DidiSoft.Pgp
Imports System
Imports System.IO

Public Class Demo
    Public Sub DecryptAndVerifyDemo()

     Dim pgpString As String = "...." ' the signed and encrypted message


        ' our private key used for decryption
        Dim PrivateKey As New FileInfo("c:\private_key.asc")
        Dim Password As String = "pass123"

     ' recipient public key used for verification of the signature
     Dim PrivateKey As New FileInfo("c:\private_key.asc")

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

     ' verify the validity of the signature and extract the encrypted string message
        Dim outputString As String
        Dim signatureIsValid 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.Exceptions..::..WrongPasswordExceptionIf the password for the decryption key is incorrect
NonPGPDataExceptionif the input data is not a valid OpenPGP encrypted message

See Also