(PureBasic) Load Certificate from .cer and Private Key from .pem
Load a certificate from a .cer and its associated private key from a .pem.
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkCert.pb"
Procedure ChilkatExample()
cert.i = CkCert::ckCreate()
If cert.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkCert::ckLoadFromFile(cert,"C:/certs_and_keys/Certificate.cer")
If success = 0
Debug CkCert::ckLastErrorText(cert)
CkCert::ckDispose(cert)
ProcedureReturn
EndIf
sbPem.i = CkStringBuilder::ckCreate()
If sbPem.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkStringBuilder::ckLoadFile(sbPem,"C:/certs_and_keys/PrivateKey.pem","utf-8")
If success = 0
Debug "Failed to load private key PEM"
CkCert::ckDispose(cert)
CkStringBuilder::ckDispose(sbPem)
ProcedureReturn
EndIf
success = CkCert::ckSetPrivateKeyPem(cert,CkStringBuilder::ckGetAsString(sbPem))
If success = 0
Debug CkCert::ckLastErrorText(cert)
CkCert::ckDispose(cert)
CkStringBuilder::ckDispose(sbPem)
ProcedureReturn
EndIf
Debug "The certificate and associated private key are now loaded and ready for signing."
CkCert::ckDispose(cert)
CkStringBuilder::ckDispose(sbPem)
ProcedureReturn
EndProcedure
|