Assembly: Starksoft.Cryptography.OpenPGP (in Starksoft.Cryptography.OpenPGP.dll)
Syntax
| C# |
|---|
public class GnuPG : IDisposable |
| Visual Basic (Declaration) |
|---|
Public Class GnuPG _ Implements IDisposable |
Remarks
GNU Privacy Guard from the GNU Project (also called GnuPG or GPG for short) is a highly regarded and supported opensource project that provides a complete and free implementation of the OpenPGP standard as defined by RFC2440. GnuPG allows you to encrypt and sign your data and communication, manage your public and privde OpenPGP keys as well as access modules for all kind of public key directories. GPG.EXE, is a command line tool that is installed with GnuPG and contains features for easy integration with other applications.
The Starksoft OpenPGP library provides classes that interface with the GPG.EXE command line tool. The Starksoft OpenPGP libraries allows any .NET application to use GPG.EXE to encrypt or decypt data using .NET IO Streams. No temporary files are required and everything is handled through streams. Any .NET Stream object can be used as long as the source stream can be read and the destination stream can be written to. But, in order for the Starksoft OpenPGP library to work you must first install the lastest version of GnuPG which includes GPG.EXE. You can obtain the latest version at http://www.gnupg.org/. See the GPG.EXE tool documentation for information on how to add keys to the GPG key ring and creating your public and private keys.
If you are new to GnuPG please install the application and then read how to generate new key pair or importing existing OpenPGP keys. You can rad more about key generation and importing at http://www.gnupg.org/gph/en/manual.html#AEN26
Encrypt File Example:
Copy Code | |
|---|---|
|
// 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 File Example:
Copy Code | |
|---|---|
|
// 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(@"c:\temp\output.txt", FileMode.Open); // create an IO.Stream object to a where you want the decrypted data to go FileStream unencryptedFile = new FileStream(@"c:\temp\unencrypted.txt", FileMode.Create); // specify our secret passphrase (if we have one) gpg.Passphrase = "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(); | |








