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
Encrypting and Decrypting MIME
Example code showing how to encrypt and decrypt MIME. Dim success As Boolean
' Create S/MIME encrypted MIME and decrypt using a digital certificate.
Dim mime As New Chilkat.Mime()
mime.UnlockComponent("anything for 30-day trial")
' Create a simple MIME message with 2 header fields and a plain-text body.
mime.AddHeaderField("field1", "value1")
mime.AddHeaderField("field2", "value2")
mime.SetBodyFromPlainText("This is a plain-text body")
TextBox1.Text = mime.GetMime()
' The text box will display this:
' field1: value1
' field2: value2
' content-type: text/plain;
' charset = "us-ascii"
' content-transfer-encoding: 7bit
'
' This is a plain-text body
' Load a certificate from a .cer file.
Dim cert As New Chilkat.Cert()
success = cert.LoadFromFile("tagtooga.cer")
If (Not success) Then
MsgBox(cert.LastErrorText)
Exit Sub
End If
success = mime.Encrypt(cert)
If (Not success) Then
MsgBox(mime.LastErrorText)
Exit Sub
End If
' Show the encrypted MIME
TextBox2.Text = mime.GetMime()
' The text box will display this:
' field1: value1
' field2: value2
' content-disposition: attachment;
' filename = "smime.p7m"
' content-transfer-encoding : base64
' content-type: application/x-pkcs7-mime;
' Name = "smime.p7m"
'
' MIIB5wYJKoZIhvcNAQcDoIIB2DCCAdQCAQAxggERMIIBDQIBADB2MGIxCzAJBgNVBAYTAlpB
' (The remainder of the MIME is nothing more than base64 data...)
' To decrypt:
success = mime.UnwrapSecurity()
If (Not success) Then
MsgBox(mime.LastErrorText)
Exit Sub
End If
TextBox3.Text = mime.GetMime()
' The result is this:
' field1: value1
' field2: value2
' content-type: text/plain;
' charset = "us-ascii"
' content-transfer-encoding: 7bit
' X-NumPartsEncrypted: 1
' X-Decrypted : yes
'
' This is a plain-text body
' If we do not want the X-NumPartsEncrypted and X-Decrypted fields added,
' set mime.UnwrapExtras = false
Dim mime2 As New Chilkat.Mime()
mime2.UnwrapExtras = False
mime2.AddHeaderField("field1", "value1")
mime2.AddHeaderField("field2", "value2")
mime2.SetBodyFromPlainText("This is a plain-text body")
mime2.Encrypt(cert)
mime2.UnwrapSecurity()
TextBox3.Text = mime2.GetMime()
' We now have the original MIME...
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.