markuspaks/xades-tools

使用XAdES签名文件并验证签名

1.0.8 2023-10-05 23:14 UTC

This package is not auto-updated.

Last update: 2024-09-20 04:08:07 UTC


README

签名

use XadesTools\Settings;
use XadesTools\Signature;
$settings = new Settings($pathToCertificate, $passphrase);
$xades = new Signature($settings);
$signedXmlAsString = $xades->signFile($file, $embed);

验证,内容提取

use XadesTools\Verification;
$xades = new Verification();
$result = $xades->verifyFile($pathToXadesFile);
if ($result) {
    $content = $res->content; // binary content or plain text for xml files
    $signTime = $res->dateSigned; // DateTime object
    $signingSubject = $res->signingSubject; // array
} else {
    // Signature does not match signed content
}

命令行使用

签名文件

php bin/sign.php file cert pass [embed] [load-content]

位置

  • file - 要签名的文件的路径。签名将创建在相同的文件夹中,并以 .XAdES 扩展名
  • cert - PKCS#12 格式(.p12)的证书 - 包含私钥
  • pass - p12 文件的密码
  • embed - 如果为 true,签名将嵌入给定的文件
  • load-content - 将文件内容加载到变量中并将其作为嵌入对象签名

结果在位于给定 file 同一目录的 file.XAdES

验证

php src/verify.php file [verbose]

位置

  • file 是 .XAdES 文件的路径
  • verbose 如果为 true,则打印有关签名时间的额外信息
  • load-content - 将文件内容加载到变量中并将其作为嵌入对象验证(不能依赖于磁盘上的文件)

验证给定 XAdES 文件中的内容,如果一切顺利,则打印 OK,否则打印错误消息。

从 XAdES 文件中提取文件

php src/extract.php file output

位置

  • file 是包含嵌入对象的 .XAdES 文件的路径
  • output 输出文件的路径