Xbase++ Requires Chilkat v11.0.0+
Xbase++
Get ETK Public Key (api-acpt.ehealth.fgov.be)
See more Belgian eHealth Platform Examples
The following URL returns JSON, which contains a PKCS7 signed data:https://api-acpt.ehealth.fgov.be/etee/v1/etks?identifier=12345678901&type=SSIN
This example extracts the signed data, validates it, and then extracts the public key from the certificate (obtained from signed content in the PKCS7)
Note: The URL above uses "12345678901" which is not valid. You should replace it with a valid number.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJarr
LOCAL oJson
LOCAL oBdPkcs7
LOCAL oCrypt
LOCAL oCert
LOCAL oPubKey
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
cJsonStr := oHttp:QuickGetStr("https://api-acpt.ehealth.fgov.be/etee/v1/etks?identifier=12345678901&type=SSIN")
IF (oHttp:LastMethodSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
RETURN
ENDIF
? cJsonStr
// The JSON contains something like this:
// [
// {
// "key": {
// "applicationIdentifier": "",
// "ssin": "12345678901"
// },
// "value": "MIAGCSq....AAAAAAAA=="
// }
// ]
// Note: The above is a JSON array (not a JSON object)
// It should be loaded into a Chilkat JSON array.
oJarr := CreateObject("Chilkat.JsonArray")
nSuccess := oJarr:Load(cJsonStr)
IF (nSuccess == 0)
? "Failed to load JSON."
oHttp:destroy()
oJarr:destroy()
RETURN
ENDIF
oJson := oJarr:ObjectAt(0)
oBdPkcs7 := CreateObject("Chilkat.BinData")
oBdPkcs7:AppendEncoded(oJson:StringOf("value"), "base64")
oJson:destroy()
// Let's verify the PKCS7, and then examine the signing cert,
// and get the signing cert's public key.
oCrypt := CreateObject("Chilkat.Crypt2")
// Validate the signedData PKCS7, and replace the contents of bdPkcs7 with the extracted signed content.
nSuccess := oCrypt:OpaqueVerifyBd(oBdPkcs7)
IF (nSuccess == 0)
? oCrypt:LastErrorText
oHttp:destroy()
oJarr:destroy()
oBdPkcs7:destroy()
oCrypt:destroy()
RETURN
ENDIF
// The signed content is the DER of a certificate.
// In other words, bdPkcs7 now contains a certificate.
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadFromBd(oBdPkcs7)
IF (nSuccess == 0)
? oCert:LastErrorText
oHttp:destroy()
oJarr:destroy()
oBdPkcs7:destroy()
oCrypt:destroy()
oCert:destroy()
RETURN
ENDIF
// Show some certificate information:
? "Subject: " + oCert:SubjectDN
? "Serial: " + oCert:SerialNumber
? "Issuer: " + oCert:IssuerDN
// Let's get the cert's public key...
oPubKey := CreateObject("Chilkat.PublicKey")
oCert:GetPublicKey(oPubKey)
// OK, you now have the public key and can do whatever is needed..
? oPubKey:KeyType
? Str(oPubKey:KeySize)
oHttp:destroy()
oJarr:destroy()
oBdPkcs7:destroy()
oCrypt:destroy()
oCert:destroy()
oPubKey:destroy()