Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Decrypt S/MIME Message in C#
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");
}
}
}
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.