C
C
Get Certificate Valid To/From Dates
Demonstrates how to get the certificate "valid from" and "valid to" dates.Chilkat C Downloads
#include <C_CkCert.h>
#include <C_CkDateTime.h>
#include <C_CkDtObj.h>
void ChilkatSample(void)
{
BOOL success;
HCkCert cert;
HCkDateTime ckdt;
HCkDtObj dt;
success = FALSE;
cert = CkCert_Create();
success = CkCert_LoadFromFile(cert,"qa_data/certs/testCert.cer");
if (success == FALSE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkCert_Dispose(cert);
return;
}
// Get the certificate valid-from date/time
ckdt = CkDateTime_Create();
CkDateTime_SetFromRfc822(ckdt,CkCert_validFromStr(cert));
// Get the local timestamp string.
printf("Valid from: %s\n",CkDateTime_getAsTimestamp(ckdt,TRUE));
// Valid from: 2017-03-17T19:00:00-05:00
// Now get the date/time as another object where we can get the individual numeric date parts.
dt = CkDtObj_Create();
CkDateTime_ToDtObj(ckdt,TRUE,dt);
printf("%d/%d/%d %d:%d\n",CkDtObj_getDay(dt),CkDtObj_getMonth(dt),CkDtObj_getYear(dt),CkDtObj_getHour(dt),CkDtObj_getMinute(dt));
// Get the certificate valid-to date/time
CkDateTime_SetFromRfc822(ckdt,CkCert_validToStr(cert));
printf("Valid to: %s\n",CkDateTime_getAsTimestamp(ckdt,TRUE));
// Valid to: 2020-03-18T18:59:59-05:00new DtObj dt;
CkDateTime_ToDtObj(ckdt,TRUE,dt);
printf("%d/%d/%d %d:%d\n",CkDtObj_getDay(dt),CkDtObj_getMonth(dt),CkDtObj_getYear(dt),CkDtObj_getHour(dt),CkDtObj_getMinute(dt));
CkCert_Dispose(cert);
CkDateTime_Dispose(ckdt);
CkDtObj_Dispose(dt);
}