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) Create CMS (PKCS7) Detached MIME SignatureDemonstrates how to add a CMS detached signature to MIME.
integer li_rc oleobject loo_Mime oleobject loo_Cert integer li_Success // This example assumes 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 // Load a certificate w/ private key for signing. 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.LoadPfxFile("qa_data/pfx/ecc256_12345.p12","12345") if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_Mime destroy loo_Cert return end if Write-Debug "Cert: " + loo_Cert.SubjectDN // Create a simple MIME message to be signed: loo_Mime.AddHeaderField("Subject","This is a test") loo_Mime.AddHeaderField("MyCustomHeader","abc123") loo_Mime.ContentType = "text/plain" loo_Mime.SetBody("This is a plain-text body.") // Examine the MIME prior to signing: Write-Debug "--- MIME prior to signing ---" Write-Debug loo_Mime.GetMime() // The MIME prior to signing looks like this: // Subject: This is a test // MyCustomHeader: abc123 // Content-Type: text/plain; format=flowed // // This is a plain-text body. // Use SHA256 as the hash algorithm in the CMS signature. loo_Mime.SigningHashAlg = "SHA256" // Add a detached signature: li_Success = loo_Mime.AddDetachedSignature(loo_Cert) if li_Success = 0 then Write-Debug loo_Mime.LastErrorText destroy loo_Mime destroy loo_Cert return end if // Examine the MIME with detached signature: Write-Debug "--- MIME with detached signature ---" Write-Debug loo_Mime.GetMime() // Content-Type: multipart/signed; boundary="----=_NextPart_6e3_c655_9641494d.b4f00501"; // protocol="application/x-pkcs7-signature"; // micalg=sha256 // // ------=_NextPart_6e3_c655_9641494d.b4f00501 // Subject: This is a test // MyCustomHeader: abc123 // Content-Type: text/plain; format=flowed // // This is a plain-text body. // ------=_NextPart_6e3_c655_9641494d.b4f00501 // Content-Transfer-Encoding: base64 // Content-Type: application/x-pkcs7-signature; name="smime.p7s" // Content-Disposition: attachment; filename="smime.p7s" // // MIID7AYJKoZIhvcNAQcCoIID3TCCA9kCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg // ggJxMIICbTCCAhOgAwIBAgIJAJuS2kgOoyr+MAkGByqGSM49BAEwWzELMAkGA1UEBhMCQVUxEzAR // BgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEUMBIG // A1UEAxMLZWNjMjU2LXRlc3QwHhcNMTYwODIzMTU0OTM5WhcNNDQwMTA4MTU0OTM5WjBbMQswCQYD // VQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQ // dHkgTHRkMRQwEgYDVQQDEwtlY2MyNTYtdGVzdDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABARy // Hd86A7+qQ4DlIfKynZaFGdGLpkU3GlQwqaVD6GIJg3QIDhaWEksYtZ9OWjNHn9a6+i/P9o5/NrdI // SP0VWDWjgcAwgb0wHQYDVR0OBBYEFGmd2DfK4c3VBTVn8ebKH2BTmRicMIGNBgNVHSMEgYUwgYKA // FGmd2DfK4c3VBTVn8ebKH2BTmRicoV+kXTBbMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1T // dGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRQwEgYDVQQDEwtlY2MyNTYt // dGVzdIIJAJuS2kgOoyr+MAwGA1UdEwQFMAMBAf8wCQYHKoZIzj0EAQNJADBGAiEAhuiwGy0lZKtK // LA13Ffc8AMTK7NsePPSfs0clXlZUR78CIQDXsJXpYsJ7tlTeockrK+6099sG/gGFTRPiQYU8juyf // LzGCAT8wggE7AgEBMGgwWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNV // BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEUMBIGA1UEAxMLZWNjMjU2LXRlc3QCCQCbktpI // DqMq/jANBglghkgBZQMEAgEFAKBpMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcN // AQkFMQ8XDTIyMDUwODE0MzM1NFowLwYJKoZIhvcNAQkEMSIEIMvNpYuymLvF68aFFe+l3NEQTdkB // 7T8U6/j+Y5FgDlIUMAoGCCqGSM49BAMCBEYwRAIgQ6migEn3Le9ciIVUP/qc2JZAJZWjpulJXY9Q // IZJ3XK0CIGZwpLOgiv7ES8958hqT9a/q7aPc1xmkaZHtsat/k+Ki // // ------=_NextPart_6e3_c655_9641494d.b4f00501-- destroy loo_Mime destroy loo_Cert |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.