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
|
EDIFACT - S/MIME Create, Sign, and EncryptCreate an EDIFACT MIME message, signs it, and then encrypts. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @mime int EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @mime, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.' IF @success = 0 BEGIN EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Assuming you have an EDIFACT document loaded into -- a string variable, set the MIME body with it: DECLARE @ediBody nvarchar(4000) SELECT @ediBody = 'UNB+IATB:1+6XPPC+LHPPC+940101:0950+1'' ...' EXEC sp_OAMethod @mime, 'SetBodyFromPlainText', NULL, @ediBody -- The call to SetBodyFromPlainText automatically set the -- content-type to "text/plain". -- However, we want: application/edifact; name=om080923.edi EXEC sp_OASetProperty @mime, 'ContentType', 'application/edifact' EXEC sp_OASetProperty @mime, 'Name', 'om080923.edi' -- We want the content-disposition to be: -- Content-Disposition: attachment; filename="om080923.edi" EXEC sp_OASetProperty @mime, 'Disposition', 'attachment' EXEC sp_OASetProperty @mime, 'Filename', 'om080923.edi' -- Content-Transfer-Encoding: quoted-printable EXEC sp_OASetProperty @mime, 'Encoding', 'quoted-printable' -- Note: MIME header fields are case insensitive. -- Add a few other header fields: EXEC sp_OAMethod @mime, 'AddHeaderField', NULL, 'Message-ID', '<CHILKAT-MID-83cf2fbf-10cb-4322-ad79-4c1097fd56f2@Matt>' EXEC sp_OAMethod @mime, 'AddHeaderField', NULL, 'MIME-VERSION', '1.0' -- Display the complete non-signed, non-encrypted MIME: EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT PRINT @sTmp0 PRINT '*********************************************' -- Sign the MIME using an opaque signature. -- (but first load a certificate) DECLARE @cert int EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @cert, 'LoadByCommonName', @success OUT, 'Chilkat Software, Inc.' IF @success = 0 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAMethod @mime, 'ConvertToSigned', @success OUT, @cert IF @success = 0 BEGIN EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- 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: EXEC sp_OASetProperty @mime, 'ContentType', 'applicaton/pkcs7-mime' -- Display the signed MIME: EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT PRINT @sTmp0 PRINT '*********************************************' -- Now encrypt it. DECLARE @encryptCert int EXEC @hr = sp_OACreate 'Chilkat.Cert', @encryptCert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @encryptCert, 'LoadByCommonName', @success OUT, 'speedi speedi' IF @success = 0 BEGIN EXEC sp_OAGetProperty @encryptCert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAMethod @mime, 'Encrypt', @success OUT, @encryptCert IF @success = 0 BEGIN EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- 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: EXEC sp_OASetProperty @mime, 'ContentType', 'applicaton/pkcs7-mime' -- Display the signed/encrypted MIME EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT PRINT @sTmp0 PRINT '*********************************************' -- Save the MIME to a file: EXEC sp_OAMethod @mime, 'SaveMime', @success OUT, 'edifact_smime.txt' IF @success = 0 BEGIN EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END PRINT 'Success!' END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.