我正在尝试验证是否已使用 iTextSharp 从服务器端对 pdf 进行数字签名,但收到以下错误:代码上的“无法解码 PKCS7SignedData 对象”
PdfPKCS7 pk = af.VerifySignature(name);
这是功能:
public string verifyPdfSignature(string pdfFile)
{
var parser = new X509CertificateParser();
PdfReader reader = new PdfReader(pdfFile);
AcroFields af = reader.AcroFields;
var names = af.GetSignatureNames();
if (names.Count == 0)
{
return "No Signature present in pdf file.";
}
foreach (string name in names)
{
if (!af.SignatureCoversWholeDocument(name))
{
return (string.Format("The signature: {0} does not cover the whole document.", name));
}
PdfPKCS7 pk = af.VerifySignature(name); //<--- ERROR HERE
var cal = pk.SignDate;
var pkc = pk.Certificates;
if (!pk.Verify())
{
return "The signature could not be verified.";
}
if (!pk.VerifyTimestampImprint())
{
return "The signature timestamp could not be verified.";
}
}
return "nothing";
}