首页 > 解决方案 > 使用 PHP 从 .pfx 文件中提取序列号

问题描述

有没有一种简单的方法使用 OpenSSL 来使用 PHP 提取证书的序列号?

我尝试使用 openssl 命令将 .pfx 文件转换为 .pem 文件,但我想知道这是否可能纯粹在 PHP 内部实现。

我目前能够从 .pem/.crt 文件中读取序列号,但不能从 .pfx 文件中读取。

感谢您提供的任何帮助

标签: phpopenssl

解决方案


您可以使用chilkat php 扩展并使用以下代码:

include("chilkat_9_5_0.php");
$cert = new CkCert();

$pfxFilename = '/your/path/to.pfx';
$pfxPassword = 'test';

$success = $cert->LoadPfxFile($pfxFilename,$pfxPassword);
if ($success != true) {
    print $cert->lastErrorText() . "\n";
    exit;
}

print 'Serial Number:' . $cert->serialNumber() . "\n";

推荐阅读