Click here to Skip to main content
15,896,383 members
Articles / Programming Languages / C#

SharpPrivacy - OpenPGP for C#

Rate me:
Please Sign up or sign in to vote.
4.92/5 (86 votes)
7 Jun 200314 min read 354.4K   8.4K   227  
SharpPrivacy is an OpenPGP implementation in C#. It can be used to encrypt and sign data, created OpenPGP compatible keys, and a lot more. This article explains how to use the library in your own .NET application or webpage to encrypt, sign, decrypt or verify OpenPGP messages.
//
// This file is part of the source code distribution of SharpPrivacy.
// SharpPrivacy is an Open Source OpenPGP implementation and can be 
// found at http://www.sharpprivacy.net
// It is released under Gnu General Public License and can be used 
// and modified as long as the result is released under GPL too. 
// For a copy of the GPL, please go to www.gnu.org/copyleft/gpl.html 
//
// PlaintextViewer.cs: 
// 	This class is a GUI for showing the plaintext after decrypting it.
//
// Author:
//	Daniel Fabian (df@sharpprivacy.net)
//
//
// Version: 0.1.0 (initial release)
//
// Changelog:
//	- 04.05.2003: Created this file.
//	- 01.06.2003: Added this header for the first beta release.
//
// (C) 2003, Daniel Fabian
//
using System;
using System.Windows.Forms;

namespace SharpPrivacy {
	public class PlaintextViewer : System.Windows.Forms.Form {
		private System.Windows.Forms.RichTextBox rtbMessage;
		private System.Windows.Forms.Button cmdClipboard;
		private System.Windows.Forms.Button cmdClose;
		
		public string MessageText {
			get {
				return rtbMessage.Text;
			}
			set {
				rtbMessage.Text = value;
			}
		}
		
		public PlaintextViewer() {
			InitializeComponent();
			this.AcceptButton = cmdClose;
			this.Resize += new System.EventHandler(this.PlaintextViewerResize);
			rtbMessage.Focus();
		}
		
		void cmdCloseClick(object sender, System.EventArgs e) {
			this.Hide();
		}
		
		void cmdClipboardClick(object sender, System.EventArgs e) {
			Clipboard.SetDataObject(rtbMessage.Text);
		}
		
		void PlaintextViewerResize(object sender, System.EventArgs e) {
			cmdClose.Location = new System.Drawing.Point(this.ClientSize.Width - 128, this.ClientSize.Height - 27);
			cmdClipboard.Location = new System.Drawing.Point(this.ClientSize.Width - 259, this.ClientSize.Height - 27);
			rtbMessage.Width = this.ClientSize.Width - 8;
			rtbMessage.Height = this.ClientSize.Height - 36; 
		}
		
		// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
		// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
		void InitializeComponent() {
			this.cmdClose = new System.Windows.Forms.Button();
			this.cmdClipboard = new System.Windows.Forms.Button();
			this.rtbMessage = new System.Windows.Forms.RichTextBox();
			this.SuspendLayout();
			// 
			// cmdClose
			// 
			this.cmdClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.cmdClose.Location = new System.Drawing.Point(432, 320);
			this.cmdClose.Name = "cmdClose";
			this.cmdClose.Size = new System.Drawing.Size(124, 24);
			this.cmdClose.TabIndex = 1;
			this.cmdClose.Text = "Close";
			this.cmdClose.Click += new System.EventHandler(this.cmdCloseClick);
			// 
			// cmdClipboard
			// 
			this.cmdClipboard.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.cmdClipboard.Location = new System.Drawing.Point(300, 320);
			this.cmdClipboard.Name = "cmdClipboard";
			this.cmdClipboard.Size = new System.Drawing.Size(124, 24);
			this.cmdClipboard.TabIndex = 0;
			this.cmdClipboard.Text = "Copy To Clipboard";
			this.cmdClipboard.Click += new System.EventHandler(this.cmdClipboardClick);
			// 
			// rtbMessage
			// 
			this.rtbMessage.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rtbMessage.Location = new System.Drawing.Point(4, 4);
			this.rtbMessage.Name = "rtbMessage";
			this.rtbMessage.ReadOnly = true;
			this.rtbMessage.Size = new System.Drawing.Size(552, 312);
			this.rtbMessage.TabIndex = 2;
			this.rtbMessage.Text = "";
			// 
			// PlaintextViewer
			// 
			this.ClientSize = new System.Drawing.Size(560, 349);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.rtbMessage,
						this.cmdClose,
						this.cmdClipboard});
			this.Text = "Decrypted Message...";
			this.ResumeLayout(false);
		}
	}
}

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
Austria Austria
My name is Daniel and I am from Austria.
When I was in High School, all I wanted to do was programming. After finishing High School, I joined a company for which I wrote a project management utility in Visual Basic 6. It was then that I realised that programming all day long was nothing I wanted to do for the rest of my life.

I quit the job and started to study computer and media security at polytechnical university in Hagenberg/Austria.

As of now, I'm still studying. I still like to program, as long as I can do something else too. Recently I switched my favorite programming language to c#. Together with a friend from university, we started a project where we implement OpenPGP (RFC2440) in c#.

Comments and Discussions