![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
EDIFACT - S/MIME Create, Sign, and Encrypt
Create an EDIFACT MIME message, signs it, and then encrypts. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% set mime = Server.CreateObject("Chilkat_9_5_0.Mime") success = mime.UnlockComponent("Anything for 30-day trial.") If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode(mime.LastErrorText) & "</pre>" End If ' Assuming you have an EDIFACT document loaded into ' a string variable, set the MIME body with it: ediBody = "UNB+IATB:1+6XPPC+LHPPC+940101:0950+1' ..." mime.SetBodyFromPlainText ediBody ' The call to SetBodyFromPlainText automatically set the ' content-type to "text/plain". ' However, we want: application/edifact; name=om080923.edi mime.ContentType = "application/edifact" mime.Name = "om080923.edi" ' We want the content-disposition to be: ' Content-Disposition: attachment; filename="om080923.edi" mime.Disposition = "attachment" mime.Filename = "om080923.edi" ' Content-Transfer-Encoding: quoted-printable mime.Encoding = "quoted-printable" ' Note: MIME header fields are case insensitive. ' Add a few other header fields: mime.AddHeaderField "Message-ID","<CHILKAT-MID-83cf2fbf-10cb-4322-ad79-4c1097fd56f2@Matt>" mime.AddHeaderField "MIME-VERSION","1.0" ' Display the complete non-signed, non-encrypted MIME: Response.Write "<pre>" & Server.HTMLEncode( mime.GetMime()) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "*********************************************") & "</pre>" ' Sign the MIME using an opaque signature. ' (but first load a certificate) set cert = Server.CreateObject("Chilkat_9_5_0.Cert") success = cert.LoadByCommonName("Chilkat Software, Inc.") If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode(cert.LastErrorText) & "</pre>" End If success = mime.ConvertToSigned(cert) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode(mime.LastErrorText) & "</pre>" End If ' Perhaps the receiver is picky and wants the content-type to be "application/pkcs7-mime" ' instead of "application/x-pkcs7-mime". In that case, simply set the content-type: mime.ContentType = "applicaton/pkcs7-mime" ' Display the signed MIME: Response.Write "<pre>" & Server.HTMLEncode( mime.GetMime()) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "*********************************************") & "</pre>" ' Now encrypt it. set encryptCert = Server.CreateObject("Chilkat_9_5_0.Cert") success = encryptCert.LoadByCommonName("speedi speedi") If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode(encryptCert.LastErrorText) & "</pre>" End If success = mime.Encrypt(encryptCert) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode(mime.LastErrorText) & "</pre>" End If ' Again, if receiver is picky and wants the content-type to be "application/pkcs7-mime" ' instead of "application/x-pkcs7-mime". In that case, simply set the content-type: mime.ContentType = "applicaton/pkcs7-mime" ' Display the signed/encrypted MIME Response.Write "<pre>" & Server.HTMLEncode( mime.GetMime()) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "*********************************************") & "</pre>" ' Save the MIME to a file: success = mime.SaveMime("edifact_smime.txt") If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode(mime.LastErrorText) & "</pre>" End If Response.Write "<pre>" & Server.HTMLEncode("Success!") & "</pre>" %> </body> </html> |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.