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
|
PKCS7 Encrypt MIMEEncrypt MIME using a digital certificate to create PKCS7 encrypted S/MIME. 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 -- Build a simple MIME message to be encrypted: EXEC sp_OAMethod @mime, 'AddHeaderField', NULL, 'Content-Type', 'text/plain' EXEC sp_OAMethod @mime, 'AddHeaderField', NULL, 'abc', '123' EXEC sp_OAMethod @mime, 'SetBody', NULL, 'This is a test' -- A digital certificate is required to create PKCS7 encrypted MIME. -- It can come from a variety of sources: .cer file, .pfx file, PEM files, -- an in-memory representation, or directly from a Windows -- registry-based certificate store. -- This example will load a certificate object from a .cer file. -- Note: Only the public-key is required to encrypt. (Decryption -- requires a private key.) 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, 'LoadFromFile', @success OUT, 'myCert.cer' IF @success = 0 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Encrypt the MIME: EXEC sp_OAMethod @mime, 'Encrypt', @success OUT, @cert IF @success = 0 BEGIN EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Display the MIME: EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT PRINT @sTmp0 -- The resulting S/MIME looks something like this: -- abc: 123 Content-Disposition: attachment; filename="smime.p7m" Content-Transfer-Encoding: base64 Content-Type: application/x-pkcs7-mime; name="smime.p7m" MIICAQYJKoZIhvcNAQcDoIIB8jCCAe4CAQAxggGFMIIBgQIBADBpMFUxCzAJBgNVBAYTAlpBMSUw IwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAoUHR5KSBMdGQuMR8wHQYDVQQDExZUaGF3dGUgQ29k ZSBTaWduaW5nIENBAhB4ouTcAmLszrGi170k1deSMA0GCSqGSIb3DQEBAQUABIIBABz59iwVufLZ QIPs0whUYMtBjIQxg5IOCxpoKJeJmLVzu9Q5Q1poxG9uYOveybS9c4wbl5A0DFfKTW5O4HhHcOHW TgcH4iqdwhiFWm/q9d5rjceJWBFQsGOcgoXSU/U2Xp+N47/+Pqyc5XJbxKnOc4YhPzO320JZsNB6 p1NGk5SNnWqgbUDmEnfH8ZPHSV7dNi2aiFALYTyLjyp0lqJCsdZ524OPTZFfusrl/9ibPAW7jKuI FgDCcBtRJvolVF8iIHxaTw4rhk0qb1KWzxvB5j9HSLdyIKIPhZbxeS10bx18YkSsBlKfdKRalQag 3oWSRdsK9/N75YHG8Pm+x9BOHUAwYAYJKoZIhvcNAQcBMBkGCCqGSIb3DQMCMA0CAToECAb+toBW txZigDhGZKSpUpuTiWvvSMemX/c79sSnMpuefVwGKFTDgXVLE2SoD5a9Yh5vcG7Mhl2IkilVwOMc fi23+g== END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.