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
(DataFlex) RSASSA-PSS Sign TextSigns text to create a PKCS7/CMS signature. The signature algorithm is RSASSA-PSS with SHA256. Note: This example requires Chilkat v9.5.0.67 or greater.
Use ChilkatAx-win32.pkg Procedure Test Handle hoCrypt Handle hoPfx Boolean iSuccess Variant vCert Handle hoCert Variant vSb Handle hoSb Integer i String sPkcs7sig String sTemp1 Boolean bTemp1 // This example requires the Chilkat Crypt API to have been previously unlocked. // See Unlock Chilkat Crypt for sample code. Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End // Get a digital certificate with private key from a .pfx // (Chilkat has many different ways to provide a cert + private key for siging. // Using a PFX is just one possible option.) Get Create (RefClass(cComChilkatPfx)) To hoPfx If (Not(IsComObjectCreated(hoPfx))) Begin Send CreateComObject of hoPfx End Get ComLoadPfxFile Of hoPfx "qa_data/rsassa-pss/privatekey.pfx" "PFX_PASSWORD" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End // Get the certificate to be used for signing. // (The typical case for a PFX is that it contains a cert with an associated private key, // as well as other certificates in the chain of authentication. The cert with the private // key should be in the first position at index 0.) Get ComGetCert Of hoPfx 0 To vCert If (IsComObject(vCert)) Begin Get Create (RefClass(cComChilkatCert)) To hoCert Set pvComObject Of hoCert To vCert End Get ComLastMethodSuccess Of hoPfx To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End Get ComSetSigningCert Of hoCrypt vCert To iSuccess // Indicate that RSASSA-PSS with SHA256 should be used. Set ComSigningAlg Of hoCrypt To "pss" Set ComHashAlgorithm Of hoCrypt To "sha256" Set ComEncodingMode Of hoCrypt To "base64_mime" // Build a string to sign Get Create (RefClass(cComChilkatStringBuilder)) To hoSb If (Not(IsComObjectCreated(hoSb))) Begin Send CreateComObject of hoSb End Move 1 To i While (i < 12) Get ComAppendInt Of hoSb i To iSuccess Get ComAppend Of hoSb " the quick brown fox jumped over the lazy dog." + (character(13)) + (character(10)) To iSuccess Move (i + 1) To i Loop Get ComGetAsString Of hoSb To sTemp1 Showln sTemp1 // The string to be encrypted looks like this: // 1 the quick brown fox jumped over the lazy dog. // 2 the quick brown fox jumped over the lazy dog. // 3 the quick brown fox jumped over the lazy dog. // 4 the quick brown fox jumped over the lazy dog. // ... // Make sure to specify the byte representation (character encoding) Set ComCharset Of hoCrypt To "utf-8" // Sign the string to get a PKCS7 detached signature in base64 format. Get pvComObject of hoSb to vSb Get ComSignSbENC Of hoCrypt vSb To sPkcs7sig Showln "Detached PCKS7 Signature:" Showln sPkcs7sig // This signature looks like this: // MIIG5wYJKoZIhvcNAQcCoIIG2DCCBtQCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg // ggL4MIIC9DCCAl2gAwIBAgIJAMPsJCT11cniMA0GCSqGSIb3DQEBCwUAMIGSMQswCQYDVQQGEwJB // VTERMA8GA1UECAwIVmljdG9yaWExEjAQBgNVBAcMCU1lbGJvdXJuZTEhMB8GA1UECgwYSW50ZXJu // ZXQgV2lkZ2l0cyBQdHkgTHRkMQ8wDQYDVQQDDAZXaWRnZXQxKDAmBgkqhkiG9w0BCQEWGWFkbWlu // QGludGVybmV0d2lkZ2V0cy5jb20wHhcNMTYxMTAxMTY1MjMyWhcNMjExMDMxMTY1MjMyWjCBkjEL // MAkGA1UEBhMCQVUxETAPBgNVBAgMCFZpY3RvcmlhMRIwEAYDVQQHDAlNZWxib3VybmUxITAfBgNV // BAoMGEludGVybmV0IFdpZ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wCgYIKoZIhvcNAwcwDgYIKoZIhvcNAwICAgCAMA0GCCqGSIb3DQMCAgFAMAcGBSsO // AwIHMA0GCCqGSIb3DQMCAgEoMIGxBgkrBgEEAYI3EAQxgaMwgaAwgZIxCzAJBgNVBAYTAkFVMREw // DwYDVQQIDAhWaWN0b3JpYTESMBAGA1UEBwwJTWVsYm91cm5lMSEwHwYDVQQKDBhJbnRlcm5ldCBX // aWRnaXRzIFB0eSBMdGQxDzANBgNVBAMMBldpZGdldDEoMCYGCSqGSIb3DQEJARYZYWRtaW5AaW50 // ZXJuZXR3aWRnZXRzLmNvbQIJAMPsJCT11cniMIGzBgsqhkiG9w0BCRACCzGBo6CBoDCBkjELMAkG // A1UEBhMCQVUxETAPBgNVBAgMCFZpY3RvcmlhMRIwEAYDVQQHDAlNZWxib3VybmUxITAfBgNVBAoM // GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEPMA0GA1UEAwwGV2lkZ2V0MSgwJgYJKoZIhvcNAQkB // FhlhZG1pbkBpbnRlcm5ldHdpZGdldHMuY29tAgkAw+wkJPXVyeIwPQYJKoZIhvcNAQEKMDCgDTAL // BglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMCASAEgYBFgBS1vtBoac6P // /NRcY3jdytoxK7xc8vEYW/PhgsbE+sP7dvu6eoRLVicoQ8RIeMh3CtPZFq1+JcL5NNzQoAotizTX // EKhiceX1mC5ocCeEvgNouxkN2Qr/X12m60rNvNl5r+GEqiqx/1fs2yRAl5sIzwPsMMY3p9tGOpy0 // 5p7sRQ== // The ASN.1 of the signature can be examined by browsing to https://lapo.it/asn1js/ , // then copy-and-paste the Base64 signature into the form and decode.. // The signature can be verified against the original data like this: Get pvComObject of hoSb to vSb Get ComVerifySbENC Of hoCrypt vSb sPkcs7sig To iSuccess Showln "Signature verified: " iSuccess Send Destroy of hoCert End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.