Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) PKCS7 Encrypt MIMEEncrypt MIME using a digital certificate to create PKCS7 encrypted S/MIME.
integer li_rc oleobject loo_Mime integer li_Success oleobject loo_Cert // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Mime = create oleobject // Use "Chilkat_9_5_0.Mime" for versions of Chilkat < 10.0.0 li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime") if li_rc < 0 then destroy loo_Mime MessageBox("Error","Connecting to COM object failed") return end if // Build a simple MIME message to be encrypted: li_Success = loo_Mime.AddHeaderField("Content-Type","text/plain") li_Success = loo_Mime.AddHeaderField("abc","123") loo_Mime.SetBody("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.) loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_Cert.LoadFromFile("myCert.cer") if li_Success = 0 then Write-Debug loo_Cert.LastErrorText destroy loo_Mime destroy loo_Cert return end if // Encrypt the MIME: li_Success = loo_Mime.Encrypt(loo_Cert) if li_Success = 0 then Write-Debug loo_Mime.LastErrorText destroy loo_Mime destroy loo_Cert return end if // Display the MIME: Write-Debug loo_Mime.GetMime() // 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== destroy loo_Mime destroy loo_Cert |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.