Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
set jsonStr [CkHttp_quickGetStr $http "https://api-acpt.ehealth.fgov.be/etee/v1/etks?identifier=12345678901&type=SSIN"]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
exit
}
puts "$jsonStr"
# 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.
set jarr [new_CkJsonArray]
set success [CkJsonArray_Load $jarr $jsonStr]
if {$success == 0} then {
puts "Failed to load JSON."
delete_CkHttp $http
delete_CkJsonArray $jarr
exit
}
# json is a CkJsonObject
set json [CkJsonArray_ObjectAt $jarr 0]
set bdPkcs7 [new_CkBinData]
CkBinData_AppendEncoded $bdPkcs7 [CkJsonObject_stringOf $json "value"] "base64"
delete_CkJsonObject $json
# Let's verify the PKCS7, and then examine the signing cert,
# and get the signing cert's public key.
set crypt [new_CkCrypt2]
# Validate the signedData PKCS7, and replace the contents of bdPkcs7 with the extracted signed content.
set success [CkCrypt2_OpaqueVerifyBd $crypt $bdPkcs7]
if {$success == 0} then {
puts [CkCrypt2_lastErrorText $crypt]
delete_CkHttp $http
delete_CkJsonArray $jarr
delete_CkBinData $bdPkcs7
delete_CkCrypt2 $crypt
exit
}
# The signed content is the DER of a certificate.
# In other words, bdPkcs7 now contains a certificate.
set cert [new_CkCert]
set success [CkCert_LoadFromBd $cert $bdPkcs7]
if {$success == 0} then {
puts [CkCert_lastErrorText $cert]
delete_CkHttp $http
delete_CkJsonArray $jarr
delete_CkBinData $bdPkcs7
delete_CkCrypt2 $crypt
delete_CkCert $cert
exit
}
# Show some certificate information:
puts "Subject: [CkCert_subjectDN $cert]"
puts "Serial: [CkCert_serialNumber $cert]"
puts "Issuer: [CkCert_issuerDN $cert]"
# Let's get the cert's public key...
set pubKey [new_CkPublicKey]
CkCert_GetPublicKey $cert $pubKey
# OK, you now have the public key and can do whatever is needed..
puts [CkPublicKey_keyType $pubKey]
puts [CkPublicKey_get_KeySize $pubKey]
delete_CkHttp $http
delete_CkJsonArray $jarr
delete_CkBinData $bdPkcs7
delete_CkCrypt2 $crypt
delete_CkCert $cert
delete_CkPublicKey $pubKey