OpenPGP signs and encrypts a String message in one pass
Namespace: DidiSoft.PgpAssembly: DidiSoft.Pgp (in DidiSoft.Pgp.dll) Version: 1.7.3.35547
Syntax
| C# |
|---|
public string SignAndEncryptString( string inputString, FileInfo privateKeyFile, string password, FileInfo publicKeyFile ) |
| Visual Basic |
|---|
Public Function SignAndEncryptString ( _ inputString As String, _ privateKeyFile As FileInfo, _ password As String, _ publicKeyFile As FileInfo _ ) As String |
| Visual C++ |
|---|
public: String^ SignAndEncryptString( String^ inputString, FileInfo^ privateKeyFile, String^ password, FileInfo^ publicKeyFile ) |
Parameters
- inputString
- Type: System..::..String
Message to be encrypted and signed
- privateKeyFile
- Type: System.IO..::..FileInfo
Private Key file, used for signing
- password
- Type: System..::..String
Private key password
- publicKeyFile
- Type: System.IO..::..FileInfo
Public key file, used for encryption
Return Value
inputString OpenPGP signed and encrypted
Remarks
* (Note that this is not the same as first encrypt and then sign, because in that case a double compression is performed.)
Compression algorithm used is the one specified through Compression
Symmetric cipher algorithm used is the one specified through Cypher
Compression algorithm used is the one specified through Compression
Symmetric cipher algorithm used is the one specified through Cypher
Examples
This sample shows how to OpenPGP sign and encrypt message and afterwards decrypt and verify it.
CopyC#
CopyVB.NET
using DidiSoft.Pgp; using System; using System.IO; public class Demo { public void SignAndEncryptDemo() { FileInfo PrivateKey = new FileInfo(@"c:\private_key.asc"); String Password = "pass123"; PGPLib pgp = new PGPLib(); string inputString = "stringToSign"; String pgpString = pgp.SignAndEncryptString(inputString, PrivateKey, Password, PublicKey); String outputString; bool verified = pgp.DecryptAndVerifyString(pgpString, PrivateKey, Password, PublicKey, out outputString); } }
Imports DidiSoft.Pgp Imports System Imports System.IO Public Class Demo Public Sub SignAndEncryptDemo() Dim PrivateKey As New FileInfo("c:\private_key.asc") Dim Password As String = "pass123" Dim pgp As New PGPLib() Dim inputString As String = "stringToSign" Dim pgpString As String = pgp.SignAndEncryptString(inputString, PrivateKey, Password, PublicKey) Dim outputString As String Dim verified As Boolean = pgp.DecryptAndVerifyString(pgpString, PrivateKey, Password, PublicKey, outputString) End Sub End Class
Exceptions
| Exception | Condition |
|---|---|
| DidiSoft.Pgp..::..PGPException | if an OpenPGP related error has occurred |
| System.IO..::..IOException | if a problem has occurred reading public key file or private key file |
| DidiSoft.Pgp..::..PGPException | if an OpenPGP related error has occurred |
| System.IO..::..IOException | I/O error |
| DidiSoft.Pgp.Exceptions..::..WrongPasswordException | if the supplied password for the private key is incorrect |
| DidiSoft.Pgp.Exceptions..::..WrongPrivateKeyException | if the supplied private key is not suitable for signing |