Decrypts an OpenPGP encrypted data stream with a private key located in a KeyStore.
Namespace: DidiSoft.PgpAssembly: DidiSoft.Pgp (in DidiSoft.Pgp.dll) Version: 1.7.3.35547
Syntax
| C# |
|---|
public string DecryptStream( Stream encryptedStream, KeyStore keyStore, string privateKeyPassword, Stream outputStream ) |
| Visual Basic |
|---|
Public Function DecryptStream ( _ encryptedStream As Stream, _ keyStore As KeyStore, _ privateKeyPassword As String, _ outputStream As Stream _ ) As String |
| Visual C++ |
|---|
public: String^ DecryptStream( Stream^ encryptedStream, KeyStore^ keyStore, String^ privateKeyPassword, Stream^ outputStream ) |
Parameters
- encryptedStream
- Type: System.IO..::..Stream
OpenPGP encrypted data stream
- keyStore
- Type: DidiSoft.Pgp..::..KeyStore
KeyStore containing the private key
- privateKeyPassword
- Type: System..::..String
Private key password
- outputStream
- Type: System.IO..::..Stream
Decrypted content
Return Value
File name of associated with the encrypted data
Remarks
The caller of this method has the obligation to close the output stream.
Examples
This example shows how to decrypt an OpenPGP encrypted stream with a private key located in a KeyStore.
CopyC#
CopyVB.NET
using System; using System.IO; using DidiSoft.Pgp; public class DecryptStreamDemo { public void Demo() { // initialize the library PGPLib pgp = new PGPLib(); // initialize theKeyStore KeyStore keyStore = new KeyStore(@"DataFiles\key.store", "password"); Stream inputFileStream = null; Stream decryptedStream = null; try { inputFileStream = new FileStream(@"c:\INPUT.pgp", FileMode.Open); string privateKeyPassword = "key password"; decryptedStream = new FileStream(@"c:\OUTPUT.txt", FileMode.Create); // decrypt and obtain the original file name string originalFileName = pgp.DecryptStream(inputFileStream, keyStore, privateKeyPassword, decryptedStream); } finally { inputFileStream.Close(); decryptedStream.Close(); } } }
Imports System Imports System.IO Imports DidiSoft.Pgp Public Class DecryptStreamDemo Public Sub Demo() ' create an instance of the library Dim pgp As New PGPLib() ' initialize theKeyStore Dim keyStore As New KeyStore("DataFiles\key.store", "password") Dim inputStream As Stream = Nothing Dim decryptedStream As Stream = Nothing Try inputStream = New FileStream("c:\INPUT.pgp", FileMode.Open) decryptedStream = New FileStream("c:\OUTPUT.txt", FileMode.Create) ' decrypt and obtain the original file name Dim originalFileName As String originalFileName = _ pgp.DecryptStream(inputStream, _ keyStore, _ "key password", _ decryptedStream) Finally inputStream.Close() decryptedStream.Close() End Try End Sub End Class
Exceptions
| Exception | Condition |
|---|---|
| System.IO..::..IOException | if an I/O error has occurred |
| DidiSoft.Pgp..::..PGPException | if an OpenPGP related error has occurred |
| DidiSoft.Pgp.Exceptions..::..WrongPrivateKeyException | If the supplied private key cannot be used to decrypt this message |
| DidiSoft.Pgp.Exceptions..::..WrongPasswordException | if the supplied password for the private key is incorrect |
| NonPGPDataException | if the input data is not a valid OpenPGP encrypted message |