php 加密cer_php-读取并解析.cer文件

我有一个证书(.cer),我必须阅读该证书的基本信息,例如到期日期.

我用php编写了这段代码

class FirmaElectronica {

public function abrirCertificado( $path ){

$cert_content = file_get_contents( $path );

$res = openssl_x509_read( $cert_content );

$data = openssl_x509_parse( $res );

var_dump( $data );

}

}

$firma = new FirmaElectronica();

$firma->abrirCertificado('gohl881206rga.cer');

但总是会收到此警告和一个空数据数组

PHP Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!

如果执行此命令,我将获取所有证书数据

openssl x509 -in gohl881206rga.cer -noout -text -inform der

用php获取证书数据的正确方法是什么?

解决方法:

include('File/X509.php');

$x509 = new File_X509();

$cert = $x509->loadX509('...');

echo $cert['tbsCertificate']['validity']['notBefore'] . "\r\n";

echo $cert['tbsCertificate']['validity']['notAfter'];

如果这样不起作用,您可以发布您想要从中获取此信息的实际证书吗?

标签:ssl,php

来源: https://codeday.me/bug/20191121/2049210.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值