Click here to Skip to main content
15,894,720 members
Articles / Programming Languages / C#

Gnu Privacy Guard (GPG/PGP) for .NET [v1.0]

Rate me:
Please Sign up or sign in to vote.
4.94/5 (17 votes)
18 Sep 20033 min read 567K   8.7K   91  
This article provides a C# wrapper class (GnuPGWrapper) that will enable use of GnuPG (the OpenPGP Internet encryption standard) within a .NET application.
  • gnupgdotnet_src.zip
    • GnuPGDotNet
      • AssemblyInfo.cs
      • bin
      • CodeCommentReport
        • banner.htm
        • banner.jpg
        • CodeCommentReportError.htm
        • commentreport.css
        • darkcorner.jpg
        • GnuPGDotNet
          • CWP0.HTM
          • CWP10.HTM
          • CWP11.HTM
          • CWP12.HTM
          • CWP13.HTM
          • CWP14.HTM
          • CWP15.HTM
          • CWP16.HTM
          • CWP17.HTM
          • CWP18.HTM
          • CWP19.HTM
          • CWP2.HTM
          • CWP20.HTM
          • CWP21.HTM
          • CWP22.HTM
          • CWP23.HTM
          • CWP24.HTM
          • CWP25.HTM
          • CWP26.HTM
          • CWP27.HTM
          • CWP28.HTM
          • CWP29.HTM
          • CWP3.HTM
          • CWP30.HTM
          • CWP31.HTM
          • CWP32.HTM
          • CWP33.HTM
          • CWP34.HTM
          • CWP35.HTM
          • CWP36.HTM
          • CWP37.HTM
          • CWP38.HTM
          • CWP39.HTM
          • CWP4.HTM
          • CWP40.HTM
          • CWP41.HTM
          • CWP42.HTM
          • CWP43.HTM
          • CWP44.HTM
          • CWP45.HTM
          • CWP46.HTM
          • CWP47.HTM
          • CWP48.HTM
          • CWP49.HTM
          • CWP5.HTM
          • CWP50.HTM
          • CWP51.HTM
          • CWP52.HTM
          • CWP53.HTM
          • CWP54.HTM
          • CWP55.HTM
          • CWP56.HTM
          • CWP57.HTM
          • CWP58.HTM
          • CWP59.HTM
          • CWP6.HTM
          • CWP60.HTM
          • CWP61.HTM
          • CWP62.HTM
          • CWP63.HTM
          • CWP64.HTM
          • CWP65.HTM
          • CWP66.HTM
          • CWP67.HTM
          • CWP68.HTM
          • CWP69.HTM
          • CWP7.HTM
          • CWP70.HTM
          • CWP71.HTM
          • CWP72.HTM
          • CWP73.HTM
          • CWP74.HTM
          • CWP75.HTM
          • CWP76.HTM
          • CWP77.HTM
          • CWP78.HTM
          • CWP79.HTM
          • CWP8.HTM
          • CWP80.HTM
          • CWP81.HTM
          • CWP82.HTM
          • CWP83.HTM
          • CWP84.HTM
          • CWP85.HTM
          • CWP86.HTM
          • CWP87.HTM
          • CWP88.HTM
          • CWP89.HTM
          • CWP9.HTM
          • CWP90.HTM
          • CWP91.HTM
          • CWP92.HTM
          • CWP93.HTM
          • CWP94.HTM
          • CWP95.HTM
          • CWP96.HTM
          • CWP97.HTM
          • CWP98.HTM
          • GnuPGDotNet.HTM
        • gradleft.jpg
        • gradtop.jpg
        • graycorner.jpg
        • minus.jpg
        • plus.jpg
        • Solution_GnuPGDotNet.HTM
        • titletile.jpg
        • vt.js
      • GnuPG.aspx
      • GnuPG.aspx.cs
      • GnuPG.aspx.resx
      • GnuPG
        • gpg.exe
        • pubring.bak
        • pubring.gpg
        • random_seed
        • secring.gpg
        • trustdb.gpg
      • GnuPGDotNet.csproj
      • GnuPGDotNet.jpg
      • GnuPGDotNet.xml
      • GnuPGWrapper.cs
      • gpg.txt
      • ReadMe.html
      • Web.config
  • gpg.zip
<?xml version="1.0"?>
<doc>
    <assembly>
        <name>GnuPGDotNet</name>
    </assembly>
    <members>
        <member name="T:Emmanuel.Cryptography.GnuPG.GnuPG">
            <summary>
            Test Page for <see cref="T:Emmanuel.Cryptography.GnuPG.GnuPGWrapper">GnuPGWrapper</see> class.
            </summary>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPG.Page_Load(System.Object,System.EventArgs)">
            <summary>
            Page Load callback function. Initialize text boxes (FromTextBox, ToTextBox) 
            with values from Web.Config file ("originator" => FromTextBox, "recipient" =>
            ToTextBox).
            </summary>
            <param name="sender">Object that raised the Load event</param>
            <param name="e">The EventArgs object that contains the event data</param>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPG.OnInit(System.EventArgs)">
            <summary>
            
            </summary>
            <param name="e"></param>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPG.InitializeComponent">
            <summary>
            Required method for Designer support - do not modify
            the contents of this method with the code editor.
            </summary>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPG.CryptAndSignButton_Click(System.Object,System.EventArgs)">
            <summary>
            Callback function when a user clicks on CryptAndSignButton. Processes the input 
            text from MessageTextBox control via GnuPG and displays the output into 
            OutputTextBox control.
            
            Please note that this function reads the following keys from Web.Config and 
            passes them to the GnuPGWrapper class: "homedirectory" and "passphrase".
            </summary>
            <param name="sender">Object that raised the Load event</param>
            <param name="e">The EventArgs object that contains the event data</param>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.ErrorMessage">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.FromTextBox">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.ToTextBox">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.MessageTextBox">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.OutputTextBox">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.CryptAndSignButton">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.CryptButton">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.SignButton">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.VerifyButton">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.DecryptButton">
            <summary>
            
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.GnuPG.ExitCodeLabel">
            <summary>
            
            </summary>
        </member>
        <member name="T:Emmanuel.Cryptography.GnuPG.GnuPGException">
            <summary>
            Specific exception thrown whenever a PGP error occurs.
            
            <p/>This class is a simple derivation from the Exception class.
            </summary>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGException.#ctor(System.String)">
            <summary>
            Constructor
            </summary>
            <param name="message">error message associated with exception</param>
        </member>
        <member name="T:Emmanuel.Cryptography.GnuPG.Commands">
            <summary>
            List (enum) of available commands (sign, encrypt, sign and encrypt, etc...)
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.Commands.Sign">
            <summary>
            Make a signature
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.Commands.Encrypt">
            <summary>
            Encrypt  data
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.Commands.SignAndEncrypt">
            <summary>
            Sign and encrypt data
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.Commands.Decrypt">
            <summary>
            Decrypt data
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.Commands.Verify">
            <summary>
            Assume that input is a signature and verify it without generating any output
            </summary>
        </member>
        <member name="T:Emmanuel.Cryptography.GnuPG.VerboseLevel">
            <summary>
            List (enum) of available verbose levels (NoVerbose, Verbose, VeryVerbose)
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.VerboseLevel.NoVerbose">
            <summary>
            Reset verbose level to 0 (no information shown during processing)
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.VerboseLevel.Verbose">
            <summary>
            Give more information during processing.
            </summary>
        </member>
        <member name="F:Emmanuel.Cryptography.GnuPG.VerboseLevel.VeryVerbose">
            <summary>
            Give full information during processing (the input data is listed in detail).
            </summary>
        </member>
        <member name="T:Emmanuel.Cryptography.GnuPG.GnuPGWrapper">
            <summary>
            This class is a wrapper class for GNU Privacy Guard (GnuPG). It execute the command 
            line program (gpg.exe) in an different process, redirects standard input (stdin),
            standard output (stdout) and standard error (stderr) streams, and monitors the 
            streams to fetch the results of the encryption/signing operation.<p/>
            
            Please note that you must have INSTALLED GnuPG AND generated/imported the 
            appropriate keys before using this class.<p/>
            
            GnuPG stands for GNU Privacy Guard and is GNU's tool for secure communication and 
            data storage. It can be used to encrypt data and to create digital signatures. It 
            includes an advanced key management facility and is compliant with the proposed 
            OpenPGP Internet standard as described in RFC 2440. As such, GnuPG is a complete 
            and free replacement for PGP.<p/>
            
            This class has been developed and tested with GnuPG v1.2.0 (MingW32)<p/>
            
            For more about GNU, please refer to http://www.gnu.org <br/>
            For more about GnuPG, please refer to http://www.gnupg.org <br/>
            For more about OpenPGP (RFC 2440), please refer to http://www.gnupg.org/rfc2440.html <br/>
            </summary>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.#ctor">
            <summary>
            Default constructor
            </summary>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.#ctor(System.String)">
            <summary>
            Constructor
            </summary>
            <param name="homeDirectory">home directory for GnuPG (where keyrings AND gpg.exe are located)</param>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.BuildOptions">
            <summary>
            Generate a string of GnuPG command line arguments, based on the properties
            set in this object (e.g. if the <see cref="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.armor">armor</see> property is true, 
            this method generates the "--armor" argument).
            </summary>
            <returns>GnuPG command line arguments</returns>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.ExecuteCommand(System.String,System.String@)">
            <summary>
            Execute the GnuPG command defined by all parameters/options/properties.
            
            <p/>Raise a GnuPGException whenever an error occurs.
            </summary>
            <param name="inputText"></param>
            <param name="outputText"></param>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.StandardOutputReader">
            <summary>
            Reader thread for standard output
            
            <p/>Updates the private variable _outputString (locks it first)
            </summary>
        </member>
        <member name="M:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.StandardErrorReader">
            <summary>
            Reader thread for standard error
            
            <p/>Updates the private variable _errorString (locks it first)
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.command">
            <summary>
            Command property: set the type of command to execute (sign, encrypt...)
            
            <p/>Defaults to SignAndEncrypt.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.armor">
            <summary>
            Boolean flag: if true, GnuPG creates ASCII armored output (text output). 
            
            <p/>Defaults to true (ASCII ouput).
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.recipient">
            <summary>
            Recipient email address - mandatory when <see cref="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.command">command</see> is Encrypt or SignAndEncrypt
            
            <p/>GnuPG uses this parameter to find the associated public key. You must have imported 
            this public key in your keyring before.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.originator">
            <summary>
            Originator email address - recommended when <see cref="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.command">command</see> is Sign or SignAndEncrypt
            
            <p/>GnuPG uses this parameter to find the associated secret key. You must have imported 
            this secret key in your keyring before. Otherwise, GnuPG uses the first secret key 
            in your keyring to sign messages. This property is mapped to the "--default-key" option.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.yes">
            <summary>
            Boolean flag; if true, GnuPG assumes "yes" on most questions.
            
            <p/>Defaults to true.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.batch">
            <summary>
            Boolean flag; if true, GnuPG uses batch mode (Never ask, do not allow 
            interactive commands).
            
            <p/>Defaults to true.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.passphrase">
            <summary>
            Passphrase for using your private key - mandatory when 
            <see cref="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.command">command</see> is Sign or SignAndEncrypt.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.homedirectory">
            <summary>
            name of the home directory (where keyrings AND gpg.exe are located)
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.passphrasefd">
            <summary>
            File descriptor for entering passphrase - defaults to 0 (standard input).
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.exitcode">
            <summary>
            Exit code from GnuPG process (0 = success; otherwise an error occured)
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.verbose">
            <summary>
            Verbose level (NoVerbose, Verbose, VeryVerbose). 
            
            <p/>Defaults to NoVerbose.
            </summary>
        </member>
        <member name="P:Emmanuel.Cryptography.GnuPG.GnuPGWrapper.ProcessTimeOutMilliseconds">
            <summary>
            Timeout for GnuPG process, in milliseconds.
            
            <p/>If the process doesn't exit before the end of the timeout period, the process is terminated (killed).
            
            <p/>Defaults to 10000 (10 seconds).
            </summary>
        </member>
    </members>
</doc>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
France France
Fell into computer software at the age of 11, founder of 3 startups, and now manager of an independent software vendor (ISV) labelled proSDK (www.prosdk.com)... And still a freeware writer and technical article author!

Comments and Discussions