Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
VB.NET to S/MIME Encrypt a File This VB.NET example shows how to S/MIME encrypt any file. The contents of a file are loaded into a MIME message as an attachment and then encrypted to create an x-pkcs7-mime enveloped message. Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Encrypt As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Encrypt = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Encrypt
'
Me.Encrypt.Location = New System.Drawing.Point(16, 24)
Me.Encrypt.Name = "Encrypt"
Me.Encrypt.Size = New System.Drawing.Size(104, 32)
Me.Encrypt.TabIndex = 0
Me.Encrypt.Text = "Encrypt"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Encrypt})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
' Encrypts any kind of file into an S/MIME encrypted message.
Private Sub Encrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Encrypt.Click
Dim mime As New Chilkat.Mime()
' Get a 30-day trial code from http:'www.chilkatsoft.com/register30.asp
mime.UnlockComponent("UnlockCode")
mime.SetBodyFromPlainText("This is a message containing a GIF image file.")
mime.AppendPartFromFile("dude.gif")
mime.SaveMime("unencrypted.txt")
' NOTE: Any MIME object can be converted to XML
mime.SaveXml("unencrypted.xml")
' Locate a certificate in the Current User Store (in the registry)
' There are many different ways of locating and using certificates
' using Cert, CertStore and CreateCS.
Dim ccs As New Chilkat.CreateCS()
Dim certStore As Chilkat.CertStore
Dim cert As Chilkat.Cert
certStore = ccs.OpenCurrentUserStore()
cert = certStore.FindCertForEmail("matt@chilkatsoft.com")
' Use the certificate for encryption.
' This creates an encrypted S/MIME message.
mime.Encrypt(cert)
mime.SaveMime("encrypted.txt")
End Sub
End Class
' Relevant keywords: mime type, mime format, mime tool, mime decoder, mime file, mime decode
' mime file, mime protocol, mime rfc, mime header, email mime, mail mime, mime decoding,
' mime attachment, mime reader, mime download, mime converter, mime content type,
' mime message, mime file type, mime html, mime downloads, mime parser, mime pdf, convert mime
' mime encoding, mime version 1.0, mime pic, mime video, mime software, mime viewer,
'
' content-disposition: attachment; filename="smime.p7m"
' content-transfer-encoding: base64
' content-type: application/x-pkcs7-mime;
' name="smime.p7m"
Important: The download for this
example does not contain the ChilkatDotNet.dll which |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.