All Projects → soukoku → PgpSharp

soukoku / PgpSharp

Licence: MIT license
Some pgp stuff in C#

Programming Languages

C#
18002 projects

About PgpSharp

This project is an attempt at providing very basic PGP functionality through a C# interface, including listing keys, encrypting/signing data, and decrypting data. It does not generate or manage keys at the moment.

Get it on NuGet

See the package page, or run

Install-Package PgpSharp

Using the lib

The main interface to use is IPgpTool. The lib provides a default impelementation that merely wraps around the GnuPG binary for windows and can be instantiated like this:

IPgpTool tool = new GnuPGTool();

By default the GnuPGTool will try to find the GnuPG binary in the standard install folder. To override the binary file path set this property:

GnuPGConfig.GnuPGExePath = @"your\path\to\gpg2.exe";

To encrypt/sign/decrypt data, you would use the ProcessData() method of the interface, and you have the option of using the StreamDataInput (for processing streams) or FileDataInput (for processing files).

// example encrypting a file
var encryptArg = new FileDataInput
{
    Armor = true,
    InputFile = @"path\to\src\file",
    OutputFile = @"path\to\output\file",
    Operation = DataOperation.Encrypt,
    Recipient = "recipient's key id",
};
tool.ProcessData(encryptArg);

// example decrypting a file
SecureString yourPassphrase = ... // somehow generate it
var decryptArg = new FileDataInput
{
    InputFile = @"path\to\encrypted\file",
    OutputFile = @"path\to\output\file",
    Operation = DataOperation.Decrypt,
    Passphrase = yourPassphrase
};
tool.ProcessData(decryptArg);

Details on which properties to use for different sign/encrypt/decrypt operation is available in the intellisense of that property. The sample WPF project also allows you to play with the different operations.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].