Verifies that the incoming string is signed from a trusted sender.
The sender public key must be already imported in theKeyStore parameter.

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

Syntax

C#
public bool VerifyString(
	string signedString,
	KeyStore keyStore,
	out string plainText
)
Visual Basic
Public Function VerifyString ( _
	signedString As String, _
	keyStore As KeyStore, _
	<OutAttribute> ByRef plainText As String _
) As Boolean
Visual C++
public:
bool VerifyString(
	String^ signedString, 
	KeyStore^ keyStore, 
	[OutAttribute] String^% plainText
)

Parameters

signedString
Type: System..::..String
OpenPGP signed string message
keyStore
Type: DidiSoft.Pgp..::..KeyStore
KeyStore object to be searched for a public key to verify the signature
plainText
Type: System..::..String%
Plain text extracted message.
Must be called with the out keyword in C#. In VB.NET is a normal ByRef invokation.

Return Value

true if a suitable public key to verify the message exists in the suppliedKeyStore object, false otherwise.

Examples

CopyC#
using System;
using DidiSoft.Pgp;

classKeyStoreVerifyString
{
    public static void Demo()
    {
        // obtain an OpenPGP signed message
        String signedString = ...

        // Extract the message and check the validity of the signature
        String plainText;
        PGPLib pgp = new PGPLib();
        KeyStore ks = new KeyStore(@"DataFiles\key.store", "password");
        bool validSignature = pgp.VerifyString(signedString,
                                                ks,
                                                out plainText);

        // Print the results
        Console.WriteLine("Extracted plain text message is " + plainText);
        if (validSignature)
        {
            Console.WriteLine("Signature is valid");
        }
        else
        {
            Console.WriteLine("Signature is invalid");
        }
    }
}
CopyVB.NET
Imports System
Imports DidiSoft.Pgp

ClassKeyStoreVerifyString
    Public Shared Sub Demo()
        ' obtain an OpenPGP signed message
        Dim signedString As String =KeyStoreSignString.Demo()

        ' Extract the message and check the validity of the signature
        Dim plainText As String
        Dim pgp As New PGPLib()
        Dim ks As New KeyStore("DataFiles\key.store", "password")
        Dim validSignature As Boolean = pgp.VerifyString(signedString, ks, plainText)

        ' Print the results
        Console.WriteLine("Extracted plain text message is " + plainText)
        If validSignature Then
            Console.WriteLine("Signature is valid")
        Else
            Console.WriteLine("Signature is invalid")
        End If
    End Sub
End Class

Exceptions

ExceptionCondition
DidiSoft.Pgp..::..PGPExceptionGeneral OpenPGP error
DidiSoft.Pgp.Exceptions..::..FileIsEncryptedExceptionIf the input signed message is not only signed but also encrypted.
NonPGPDataExceptionif the input data is not a valid OpenPGP message

See Also