Decrypts OpenPGP encrypted string message

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

Syntax

C#
public string DecryptString(
	string encryptedString,
	KeyStore keyStore,
	string privateKeyPassword
)
Visual Basic
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.Pgp..::..KeyStore
KeyStore object that contains the decryption key
privateKeyPassword
Type: System..::..String
Password of the private decryption key located in theKeyStore

Return Value

decrypted plain text string

Examples

CopyC#
using System;
using DidiSoft.Pgp;

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

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.Pgp

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

        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 thisKeyStore that can decrypt the message

See Also