OpenPGP signs a string message.

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

Syntax

C#
public string SignString(
	string stringToSign,
	KeyStore keyStore,
	long privateKeyId,
	string privateKeyPassword
)
Visual Basic
Public Function SignString ( _
	stringToSign As String, _
	keyStore As KeyStore, _
	privateKeyId As Long, _
	privateKeyPassword As String _
) As String
Visual C++
public:
String^ SignString(
	String^ stringToSign, 
	KeyStore^ keyStore, 
	long long privateKeyId, 
	String^ privateKeyPassword
)

Parameters

stringToSign
Type: System..::..String
message to be signed
keyStore
Type: DidiSoft.Pgp..::..KeyStore
key store containing the signing key
privateKeyId
Type: System..::..Int64
signing key Id
privateKeyPassword
Type: System..::..String
signing key password

Return Value

OpenPGP signed string

Examples

CopyC#
using System;
using DidiSoft.Pgp;

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

        long signingKeyId = ks.GetKeyIdForKeyIdHex("8BA4CF8F");
        string signingKeyPassword = "password";

        // if this key store contains a key with the desired recipient userId - encrypt,
        // otherwise notify that there is no such key
        PGPLib pgp = new PGPLib();

        string plainText = "Hello World";
        string signedString = pgp.SignString(plainText, ks, 
                                             signingKeyUserId,
                                             signingKeyPassword);
    }
}
CopyVB.NET
Imports System
Imports DidiSoft.Pgp

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

        Dim signingKeyId As Long = ks.GetKeyIdForKeyIdHex("8BA4CF8F")
        Dim signingKeyPassword As String = "password"

        Dim pgp As New PGPLib()

        Dim plainText As String = "Hello World"
        Dim signedString As String = pgp.SignString(plainText, ks, signingKeyUserId, signingKeyPassword)
    End Sub
End Class

Exceptions

ExceptionCondition
DidiSoft.Pgp..::..PGPExceptionif a signing error has occurred
DidiSoft.Pgp.Exceptions..::..WrongPasswordExceptionif the supplied password for the private key is incorrect
DidiSoft.Pgp.Exceptions..::..WrongPrivateKeyExceptionif there is no private key in this KeyStore with such Key Id

See Also