Decrypts OpenPGP encrypted string message

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

Syntax

C#
public string DecryptString(
	string encryptedString,
	KeyStore keyStore,
	string privateKeyPassword
)
Visual Basic (Declaration)
Public Function DecryptString ( _
	encryptedString As String, _
	keyStore As KeyStore, _
	privateKeyPassword As String _
) As String
Visual C++
public:
String^ DecryptString(
	String^ encryptedString, 
	KeyStore^ keyStore, 
	String^ privateKeyPassword
)

Parameters

encryptedString
Type: System..::.String
OpenPGP encrypted string message
keyStore
Type: DidiSoft..::.KeyStore
KeyStore object that contains the decryption key
privateKeyPassword
Type: System..::.String
Password of the private decryption key located in the KeyStore

Return Value

decrypted plain text string

Examples

CopyC#
using System;
using DidiSoft;

class DecryptStringWithKeyStore
{
 public void Demo()
{
  // initialize the key store
  KeyStore ks = new KeyStore(@"DataFiles\key.store", "changeit");

try {
          PGPLib pgp = new PGPLib();

           // OpenPGP enrypted string
           string encryptedString = ... 

           string plainText = pgp.DecryptString(encryptedString, ks, "password");
  }
  catch (ArgumentException) 
  {
           Console.WriteLine("No suitable deryption key was found in this key store.");
   }
 }
}
CopyVB.NET
Imports System
Imports DidiSoft

Class DecryptStringWithKeyStore
    Public Sub Demo()
        ' initialize the key store
        Dim ks As New KeyStore("DataFiles\key.store", "changeit")

        Try
            Dim pgp As New PGPLib()

            ' OpenPGP encrypted string
            Dim encryptedString As String = ...

            Dim plainText As String = pgp.DecryptString(encryptedString, ks, "password")
        Catch generatedExceptionName As ArgumentException
            Console.WriteLine("No suitable deryption key was found in this key store.")
        End Try
    End Sub
End Class

Exceptions

ExceptionCondition
System..::.ArgumentExceptionIf there is no private key in this KeyStore that can decrypt the message

See Also