如何以编程方式测试 X509 ?* 证书是否过期?
他们是直接的加密 API 吗?
或者我必须获取 not_after 时间并在我的代码中手动检查它?
你没有说是哪种语言,所以我还是总结一下:
php
$data = openssl_x509_parse(file_get_contents('/path/to/cert.crt'));
$validFrom = date('Y-m-d H:i:s', $data['validFrom_time_t']);
$validTo = date('Y-m-d H:i:s', $data['validTo_time_t']);
Java X509证书 http://docs.oracle.com/javase/7/docs/api/java/security/cert/X509Certificate.html
InputStream inStream = null;
try (InputStream inStream = new FileInputStream("fileName-of-cert")) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream);
// check if valid on specific date (now set for today)
cert.checkValidity(new Date());
// Date nBefore = cert.getNotBefore();
// Date nAfter = cert.getNotAfter();
}
C++
using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
// The path to the certificate.
String^ Certificate = "Certificate.cer";
// Load the certificate into an X509Certificate object.
X509Certificate^ cert = X509Certificate::CreateFromCertFile( Certificate );
// Get the value.
String^ results = cert->GetExpirationDateString();
// Display the value to the console.
Console::WriteLine( results );
}
C
X509 *x
time_t *ptime;
i=X509_cmp_time(X509_get_notBefore(x), ptime);
i=X509_cmp_time(X509_get_notAfter(x), ptime);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)