(PureBasic) ZATCA Load Certificate and Private Key from PEM Files
Demonstrates how to load a certificate and private key from a pair of PEM files.
IncludeFile "CkPrivateKey.pb"
IncludeFile "CkCert.pb"
Procedure ChilkatExample()
; The LoadFromFile method will automatically detect the file format..
cert.i = CkCert::ckCreate()
If cert.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkCert::ckLoadFromFile(cert,"qa_data/zatca/cert.pem")
If success <> 1
Debug CkCert::ckLastErrorText(cert)
CkCert::ckDispose(cert)
ProcedureReturn
EndIf
Debug CkCert::ckSubjectCN(cert)
; Load the private key.
privKey.i = CkPrivateKey::ckCreate()
If privKey.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkPrivateKey::ckLoadPemFile(privKey,"qa_data/zatca/ec-secp256k1-priv-key.pem")
If success <> 1
Debug CkPrivateKey::ckLastErrorText(privKey)
CkCert::ckDispose(cert)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndIf
Debug "Key Type: " + CkPrivateKey::ckKeyType(privKey)
; Associate the private key with the certificate.
success = CkCert::ckSetPrivateKey(cert,privKey)
If success <> 1
Debug CkCert::ckLastErrorText(cert)
CkCert::ckDispose(cert)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndIf
Debug "Success."
CkCert::ckDispose(cert)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndProcedure
|