Unicode C
Unicode C
Get Certificate Valid To/From Dates
Demonstrates how to get the certificate "valid from" and "valid to" dates.Chilkat Unicode C Downloads
#include <C_CkCertW.h>
#include <C_CkDateTimeW.h>
#include <C_CkDtObjW.h>
void ChilkatSample(void)
{
BOOL success;
HCkCertW cert;
HCkDateTimeW ckdt;
HCkDtObjW dt;
success = FALSE;
cert = CkCertW_Create();
success = CkCertW_LoadFromFile(cert,L"qa_data/certs/testCert.cer");
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
// Get the certificate valid-from date/time
ckdt = CkDateTimeW_Create();
CkDateTimeW_SetFromRfc822(ckdt,CkCertW_validFromStr(cert));
// Get the local timestamp string.
wprintf(L"Valid from: %s\n",CkDateTimeW_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 = CkDtObjW_Create();
CkDateTimeW_ToDtObj(ckdt,TRUE,dt);
wprintf(L"%d/%d/%d %d:%d\n",CkDtObjW_getDay(dt),CkDtObjW_getMonth(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt),CkDtObjW_getMinute(dt));
// Get the certificate valid-to date/time
CkDateTimeW_SetFromRfc822(ckdt,CkCertW_validToStr(cert));
wprintf(L"Valid to: %s\n",CkDateTimeW_getAsTimestamp(ckdt,TRUE));
// Valid to: 2020-03-18T18:59:59-05:00new DtObj dt;
CkDateTimeW_ToDtObj(ckdt,TRUE,dt);
wprintf(L"%d/%d/%d %d:%d\n",CkDtObjW_getDay(dt),CkDtObjW_getMonth(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt),CkDtObjW_getMinute(dt));
CkCertW_Dispose(cert);
CkDateTimeW_Dispose(ckdt);
CkDtObjW_Dispose(dt);
}