Xbase++
Xbase++
Create Egypt ITIDA CAdES-BES .p7s Signature (with strings in-memory)
See more Egypt ITIDA Examples
Demonstrates how to create a .p7s signature that fits Egypt's ITIDA requirements.Note: This example requires Chilkat v9.5.0.75 or greater.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oCrypt
LOCAL oCert
LOCAL oCmsOptions
LOCAL oJsonSigningAttrs
LOCAL cTextToSign
LOCAL cSigBase64
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oCrypt := CreateObject("Chilkat.Crypt2")
oCert := CreateObject("Chilkat.Cert")
// There are many ways to load the certificate.
// This example was created for a customer using an ePass2003 USB token.
// Assuming the USB token is the only source of a hardware-based private key..
nSuccess := oCert:LoadFromSmartcard("")
IF (nSuccess != 1)
? oCert:LastErrorText
oCrypt:destroy()
oCert:destroy()
RETURN
ENDIF
// Tell the crypt component to use this cert.
nSuccess := oCrypt:SetSigningCert(oCert)
IF (nSuccess != 1)
? oCrypt:LastErrorText
oCrypt:destroy()
oCert:destroy()
RETURN
ENDIF
oCmsOptions := CreateObject("Chilkat.JsonObject")
// Setting "DigestData" causes OID 1.2.840.113549.1.7.5 (digestData) to be used.
oCmsOptions:UpdateBool("DigestData", 1)
oCmsOptions:UpdateBool("OmitAlgorithmIdNull", 1)
oCrypt:CmsOptions := oCmsOptions:Emit()
// The CadesEnabled property applies to all methods that create CMS/PKCS7 signatures.
// To create a CAdES-BES signature, set this property equal to true.
oCrypt:CadesEnabled := 1
oCrypt:HashAlgorithm := "sha256"
oJsonSigningAttrs := CreateObject("Chilkat.JsonObject")
oJsonSigningAttrs:UpdateInt("contentType", 1)
oJsonSigningAttrs:UpdateInt("signingTime", 1)
oJsonSigningAttrs:UpdateInt("messageDigest", 1)
oJsonSigningAttrs:UpdateInt("signingCertificateV2", 1)
oCrypt:SigningAttributes := oJsonSigningAttrs:Emit()
// By default, all the certs in the chain of authentication are included in the signature.
// If desired, we can choose to only include the signing certificate:
oCrypt:IncludeCertChain := 0
// Make sure we sign the utf-8 byte representation of the JSON string
oCrypt:Charset := "utf-8"
// Create the CAdES-BES signature.
cTextToSign := '"issuer""address""branchID""0""country""EG""regionCity...'
oCrypt:EncodingMode := "base64"
cSigBase64 := oCrypt:SignStringENC(cTextToSign)
IF (oCrypt:LastMethodSuccess == 0)
? oCrypt:LastErrorText
oCrypt:destroy()
oCert:destroy()
oCmsOptions:destroy()
oJsonSigningAttrs:destroy()
RETURN
ENDIF
? "Base64 signature:"
? cSigBase64
oCrypt:destroy()
oCert:destroy()
oCmsOptions:destroy()
oJsonSigningAttrs:destroy()