【发布时间】:2023-02-20 14:47:54
【问题描述】:
我有一个特定的需求:在我的软件中我生成了一个 TXT 文档,我需要使用 CAdES 方法对该文件进行签名并生成一个分离的 P7S 文件,但我没有找到任何有关如何执行此操作的信息。
那么我的步骤是什么
- 使用我需要的所有内容生成此 TXT
- 使用有效的 PFX 证书(我已经拥有)对此进行签名
- 根据这个先前的签名生成一个 P7S 文件
我尝试使用函数 openssl_pkcs7_sign,但我只有一个错误 HTTP 500 并且没有捕获任何异常,所以我真的不知道发生了什么。
这是我尝试过的一个简单示例(我对该函数进行了很多不同的调用,这是最后一个):
// the message you want to sign so that recipient can be sure it was you that
// sent it
$data = 'Here is the content';
// save message to file
$fp = fopen("licence.txt", "w");
fwrite($fp, $data);
fclose($fp);
// encrypt it
if (openssl_pkcs7_sign("license.txt", "licence.txt.p7s", "my_pfx_file.pfx",
array("file://some_folder/my_pfx_file.pfx"),
null
)) {
// message signed - send it!
exit('foi');
} else {
exit('falhou');
}
我希望有人能帮助我!
【问题讨论】:
标签: php codeigniter digital-signature pfx