User
User

Reputation: 145

get validTo date from x509 certificate using openssl-php

Need to get validTo (expiry) date from x509 certificate and validate with current date. Am using openssl_x509_parse($crtdata) to parse the certificate, any thought on how to get the validTo date from the resulting array. Thanks.

Upvotes: 0

Views: 2511

Answers (1)

doptimusprime
doptimusprime

Reputation: 9395

Why do not you use print_r which will print the array and gives out the indices or key you need?

I think you can try the following

 $arr = openssl_x509_parse($crtdata);
 /*To get the validTo*/
 $validTo = $arr['ValidTo_time_t'];

This is given as an example at PHP manual page of openssl_x509_parse.

I hope this would help you. But you may face issue in future. Consider this program to update if you plan to update PHP version and test it well.

Upvotes: 1

Related Questions