![]() |
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
(PowerBuilder) Create PEM-encoded PKCS#7 Detached SignatureSee more Digital Signatures ExamplesDemonstrates how to create a PKCS7 PEM-encoded object containing a detached signature.
integer li_rc oleobject loo_Cert integer li_Success oleobject loo_Crypt string ls_TextToSign string ls_SigBase64 oleobject loo_Sb integer li_Crlf // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") if li_rc < 0 then destroy loo_Cert MessageBox("Error","Connecting to COM object failed") return end if // Load the cert and private key. li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/myCertAndKey.p12","password") if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_Cert return end if loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") li_Success = loo_Crypt.SetSigningCert(loo_Cert) if li_Success <> 1 then Write-Debug loo_Crypt.LastErrorText destroy loo_Cert destroy loo_Crypt return end if // Use SHA-256 loo_Crypt.HashAlgorithm = "sha256" // Hash the utf-8 byte representation of the string loo_Crypt.Charset = "utf-8" // Return the result in base64 loo_Crypt.EncodingMode = "base64Mime" // Sign some text to create a detached signature (i.e. a signature that does not include the signed data) ls_TextToSign = "This is the text to be hashed and signed." ls_SigBase64 = loo_Crypt.SignStringENC(ls_TextToSign) if loo_Crypt.LastMethodSuccess <> 1 then Write-Debug loo_Crypt.LastErrorText destroy loo_Cert destroy loo_Crypt return end if Write-Debug ls_SigBase64 // The result: // MIIWbgYJKoZIhvcNAQcCoIIWXzCCFlsCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg // ghMXMIIFuzCCA6OgAwIBAgIIVwoRl0LE48wwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVQx // ... // ... // If we want it in PEM format with just LF line-endings: loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") // Just LF line endings, not CRLF. li_Crlf = 0 loo_Sb.AppendLine("-----BEGIN PKCS7-----",li_Crlf) loo_Sb.Append(ls_SigBase64) loo_Sb.AppendLine("-----END PKCS7-----",li_Crlf) loo_Sb.ToLF() // Save to a file. loo_Sb.WriteFile("c:/temp/qa_output/sig.pem","utf-8",0) // Examine.. Write-Debug loo_Sb.GetAsString() // Result is: // -----BEGIN PKCS7----- // MIIWbgYJKoZIhvcNAQcCoIIWXzCCFlsCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg // ghMXMIIFuzCCA6OgAwIBAgIIVwoRl0LE48wwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVQx // DjAMBgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3RhbGlzIFMucC5BLi8wMzM1ODUyMDk2NzEnMCUG // A1UEAwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBSb290IENBMB4XDTExMDkyMjExMjIwMloXDTMw // MDkyMjExMjIwMlowazELMAkGA1UEBhMCSVQxDjAMBgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3Rh // bGlzIFMucC5BLi8wMzM1ODUyMDk2NzEnMCUGA1UEAwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBS // b290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAp8bEpSmkLO/lGMWwUKNvUTuf // ClrJwkg4CsIcoBh/kbWHuUA/3R1oHwiD1S0eiKD4j1aPbZkCkpAW1V8IbInX4ay8IMKx4INRimlN // AJZaby/ARH6jDuSRzVju3PvHHkVH3Se5CAGfpiEd9UEtL0z9KK3giq0itFZljoZUj5NDKd45Rnij // MCO6zfB9E1fAXdKDa0hMxKufgFpbOr3JpyI/gCczWw63igxdBzcIy2zSekciRDXFzMwujt0q7bd9 // ... // ... // -----END PKCS7----- destroy loo_Cert destroy loo_Crypt destroy loo_Sb |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.