OpenPGP encrypts given data stream using the first available public OpenPGP key from a key file
Namespace: DidiSoft.PgpAssembly: DidiSoft.Pgp (in DidiSoft.Pgp.dll) Version: 1.7.3.35547
Syntax
| C# |
|---|
public void EncryptStream( Stream dataStream, KeyStore keyStore, long keyId, Stream outputStream, bool asciiArmor ) |
| Visual Basic |
|---|
Public Sub EncryptStream ( _ dataStream As Stream, _ keyStore As KeyStore, _ keyId As Long, _ outputStream As Stream, _ asciiArmor As Boolean _ ) |
| Visual C++ |
|---|
public: void EncryptStream( Stream^ dataStream, KeyStore^ keyStore, long long keyId, Stream^ outputStream, bool asciiArmor ) |
Parameters
- dataStream
- Type: System.IO..::..Stream
Data to be encrypted
- keyStore
- Type: DidiSoft.Pgp..::..KeyStore
KeyStore instance containing the recipient public key
- keyId
- Type: System..::..Int64
Key Id of the recipient public key
- outputStream
- Type: System.IO..::..Stream
OpenPGP encrypted output
- asciiArmor
- Type: System..::..Boolean
If true the encrypted file will be in ASCII armored format, otherwise in binary format
Remarks
A special string '_CONSOLE' will be used as internal file name for the encryped data
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
using System.IO; using DidiSoft.Pgp; class EncryptStreamDemo { public void Demo() { KeyStore keyStore = new KeyStore(@"c:\my.keystore", "password123"); long recipientKeyId = keyStore.GetKeyIdForKeyIdHex("8BA4CF8F"); PGPLib pgp = new PGPLib(); Stream inputStream = File.OpenRead(@"DataFiles\INPUT.txt"); Stream encryptedStream = File.OpenWrite(@"DataFiles\OUTPUT.pgp"); bool asciiArmor = true; pgp.EncryptStream(inputStream, keyStore, recipientKeyId, encryptedStream, asciiArmor); } }
Imports System.IO Imports DidiSoft.Pgp Class EncryptStreamDemo Public Sub Demo() Dim keyStore As New KeyStore("c:\my.keystore", "password123") Dim recipientKeyId As Long = keyStore.GetKeyIdForKeyIdHex("8BA4CF8F") Dim pgp As New PGPLib() Dim inputStream As Stream = File.OpenRead("DataFiles\INPUT.txt") Dim encryptedStream As Stream = File.OpenWrite("DataFiles\OUTPUT.pgp") Dim asciiArmor As Boolean = True pgp.EncryptStream(inputStream, keyStore, recipientKeyId, encryptedStream, asciiArmor) End Sub End Class
Exceptions
| Exception | Condition |
|---|---|
| DidiSoft.Pgp.Exceptions..::..WrongPublicKeyException | If the supplied public key file is not usable |
| DidiSoft.Pgp..::..PGPException | if an OpenPGP related error has occurred |
| System.IO..::..IOException | I/O error |