Encrypts a file with a public key and a passphrase.
The passphrase can be used to decrypt the file if the corresponding private key is lost.
Example GnuPG command:
gpg -r [public key user id] -c -e [dataFileName]
Namespace: DidiSoft.PgpThe passphrase can be used to decrypt the file if the corresponding private key is lost.
Example GnuPG command:
gpg -r [public key user id] -c -e [dataFileName]
Assembly: DidiSoft.Pgp (in DidiSoft.Pgp.dll) Version: 1.7.3.35547
Syntax
| C# |
|---|
public void EncryptFilePBE( string dataFileName, Stream publicKeyStream, string passphrase, string outputFileName, bool asciiArmor, bool withIntegrityCheck ) |
| Visual Basic |
|---|
Public Sub EncryptFilePBE ( _ dataFileName As String, _ publicKeyStream As Stream, _ passphrase As String, _ outputFileName As String, _ asciiArmor As Boolean, _ withIntegrityCheck As Boolean _ ) |
| Visual C++ |
|---|
public: void EncryptFilePBE( String^ dataFileName, Stream^ publicKeyStream, String^ passphrase, String^ outputFileName, bool asciiArmor, bool withIntegrityCheck ) |
Parameters
- dataFileName
- Type: System..::..String
File name to be encrypted (absolute or relative path)
- publicKeyStream
- Type: System.IO..::..Stream
Public key to encrypt with (absolute or relative path)
- passphrase
- Type: System..::..String
Additional passphrase that can be used to decrypt the file instead of using the private key
- outputFileName
- Type: System..::..String
File location for the output encrypted file (absolute or relative path)
- asciiArmor
- Type: System..::..Boolean
Should the output be in ASCII armored format
- withIntegrityCheck
- Type: System..::..Boolean
Should integrity check information be added to the file.
Remarks
The caller has the obligation to close the public key stream.
Examples
The example below shows how to OpenPGP encrypt a file with both public key and a password
CopyC#
CopyVB.NET
using System.IO; using DidiSoft.Pgp; class EncryptDemo { public void Demo() { PGPLib pgp = new PGPLib(); bool asciiArmor = true; bool withIntegrityCheck = true; pgp.EncryptFilePBE(@"DataFiles\INPUT.txt", @"DataFiles\public_key.asc", "alternative_password", @"DataFiles\OUTPUT.pgp", asciiArmor, withIntegrityCheck); } }
Imports System.IO Imports DidiSoft.Pgp Class EncryptDemo Public Sub Demo() Dim pgp As New PGPLib() Dim asciiArmor As Boolean = True Dim withIntegrityCheck As Boolean = False pgp.EncryptFilePBE("DataFiles\INPUT.txt", _ "DataFiles\public_key.asc", _ "alternative_password", _ "DataFiles\OUTPUT.pgp", _ asciiArmor, _ withIntegrityCheck) End Sub End Class
Exceptions
| Exception | Condition |
|---|---|
| DidiSoft.Pgp.Exceptions..::..WrongPublicKeyException | If the supplied public key file is not usable |
| DidiSoft.Pgp..::..PGPException | General encryption error |
| System.IO..::..IOException | I/O error |