C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



C# Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

Decrypt S/MIME Message in C#

Download C# Project Files and Source Code

This C# S/MIME example program shows how to decrypt an encrypted MIME message. Once decrypted, the data can easily be accessed.


		// Loads an encrypted MIME message, unwraps the security envelopes, and determines
		// if the decryption was successful.  
		private void Decrypt_Click(object sender, System.EventArgs e)
		{
			Chilkat.Mime mime = new Chilkat.Mime();

			// Any string passed to UnlockComponent begins the 30-day trial
			mime.UnlockComponent("30-day trial");
			mime.LoadMimeFile("encrypted.txt");

			// Determine if this is an encrypted message or not.
			if (mime.IsEncrypted())
			{
				listBox1.Items.Add("Message is encrypted");
			}
			else
			{
				listBox1.Items.Add("Message is not encrypted");
			}

			// Unwrap the security.  
			// The results are stored within the Mime object and can be queried
			// afterwards. 
			// The UnwrapSecurity does all decryption and signature validation,
			// regardless of how complex the MIME message may be.
			bool decryptSuccess = mime.UnwrapSecurity();
			if (decryptSuccess)
			{
				listBox1.Items.Add("Message has been decrypted");
			}
			else
			{
				listBox1.Items.Add("Message not decrypted");
			}

			// Save the decrypted MIME message.
			mime.SaveMime("decrypted.txt");
			// (You can convert any MIME message to XML too.)
			mime.SaveXml("decrypted.xml");

			// Get the first encrypting certificate.
			// In complex cases where the MIME is nested and contains
			// other encrypted MIME messages, there will be more than
			// one encrypting certificate.
			Chilkat.Cert cert;
			cert = mime.GetEncryptCert(0);
			listBox1.Items.Add("Encrypted By: " + cert.SubjectDN);
			
			// This example uses a MIME message that included a GIF attachment.
			// Save the GIF to a file.
			Chilkat.Mime gifAttachment;
			gifAttachment = mime.GetPart(1);
			gifAttachment.SaveBody("dude.gif");
		
		}
	}
}

 

 

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser