OpenPGP Component for .NET

Free, open source, easy to use .NET Component for signing, encrypting and decryption data or documents with the free and open source GNU OpenPGP project called GnuPG (or GPG for short).

Download

Change Log

Issue Tracker

Browse Source Code

Documentation

License

  • Free software with permissive MIT license - no GPL restrictions.
  • Multiple VB.NET and C# examples.
  • Interfaces directly with the GnuPG GPG.EXE command line tool to sign, encrypt and decrypt data using .NET Streams.
  • Locates the GPG.EXE executable  two different ways - the Windows registery or by user supplied path.
  • Retrieve a collection or DataSet of the keys loaded in the local key ring.
  • Use as a DLL or add the source code directly to your project.
  • Encrypt and decrypt examples given in C# and VB.NET.
  • Asynchronous encryption and decryption examples given in C# and VB.NET.
  • Integrated Visual Studio.NET help documentation.
  • Accepts any System.IO.Stream object from reading and writing encryption data.
  • Output type either as ASCII Armor or Binary
  • Supports optional passphrases when decryption data.
  • Both Encrypt and Decrypt methods have corresponding EncryptAsync and DecryptAsync methods to support background processing.
  • Supports the new Microsoft Asynchronous Model so you can just fire and forget asynchronous calls (no Begin/End needed).
  • Written in 100% managed C# code.
  • Requires .NET 2.0, 3.0, or 3.5 and GPG.EXE or GPG2.EXE executable.

Encrypt example:

  // create a new GnuPG object
  GnuPG gpg = new GnuPG();

  // specify a recipient that is already on the key-ring  
  gpg.Recipient = "myfriend@domain.com";

  // create an IO.Stream object to the source of the data and open it
  FileStream sourceFile = new FileStream(@"c:\temp\source.txt", FileMode.Open); 
  // create an IO.Stream object to a where I want the encrypt data to go
  FileStream outputFile = new FileStream(@"c:\temp\output.txt", FileMode.Create);

  // encrypt the data using IO Streams - any type of input and output IO Stream can be used
  // as long as the source (input) stream can be read and the destination (output) stream  
  // can be written to
  gpg.Encrypt(sourceFile, outputFile);

  // close the files
  sourceFile.Close();
  outputFile.Close();


Decrypt example:
  // create a new GnuPG object
  GnuPG gpg = new GnuPG();

  // create an IO.Stream object to the encrypted source of the data and open it  
  FileStream encryptedFile = new FileStream(@"output.txt", FileMode.Open);
  // create an IO.Stream object to a where you want the decrypted data to go
  FileStream unencryptedFile = new FileStream(@"unencrypted.txt", FileMode.Create);

  // specify our secret passphrase (if one is used)
  gpg.Passphrase = "your secret passphrase";            

  // decrypt the data using IO Streams - any type of input and output IO Stream can be used
  // as long as the source (input) stream can be read and the destination (output) stream  
  // can be written to
  gpg.Decrypt(encryptedFile, unencryptedFile);

  // close the files
  encryptedFile.Close();
  unencryptedFile.Close();