【发布时间】:2022-01-21 03:17:39
【问题描述】:
我目前正在使用 Python 开发一个数字签名项目,该项目可以在 PDF 文档上创建数字签名并对其进行验证。我能够使用以下代码向 PDF 文件添加单个数字签名:
PDFNet.Initialize()
doc = PDFDoc(pdf_path)
page1 = doc.GetPage(1)
# Create signature field
sign_field = doc.CreateDigitalSignatureField("Signature")
widgetAnnot = SignatureWidget.Create(doc, Rect(0, 0, 100, 100), sign_field)
page1.AnnotPushBack(widgetAnnot)
sign_field.SignOnNextSave(pkcs12_path, "")
# Save file
output_path = get_only_path(pdf_path) + "output.pdf"
doc.Save(output_path, SDFDoc.e_incremental)
PDFNet.Terminate()
我还可以使用以下代码验证文档:
# Get certificate
dsfield_iter = doc.GetDigitalSignatureFieldIterator()
while dsfield_iter.HasNext():
sign_field = dsfield_iter.Current()
cert = sign_field.GetSignerCertFromCMS()
dsfield_iter.Next()
# Save certificate for verification
cert_path = get_only_path(pdf_path) + "certificate.cer"
with open(cert_path, "wb") as cer:
# cert.GetData() return DER format
cer.write(cert.GetData())
# Verifying signature
opts = VerificationOptions(VerificationOptions.e_compatibility_and_archiving)
opts.AddTrustedCertificate(cert_path)
result = doc.VerifySignedDigitalSignatures(opts)
但是,我有一个问题。我希望多个人能够使用他们在不同签名字段中的自签名证书在同一个文档上签名,并且还能够验证该文档。我将我的代码用于相同的过程,但在多人签名后无法验证签名。我想得到这方面的帮助,请分享你的想法:)
【问题讨论】:
-
“我希望多个人能够在同一个文档上签名”。您是在添加之前的签名后一次添加一个吗?还是在第一次签名之前,PDF 中都存在空的签名字段?
-
感谢您的回复。我希望能够一次添加一个签名,它可以是没有签名的文档或以前签名的文档。
-
您关心的只是 PDFTron 验证,还是您希望在任何/所有进行签名验证的供应商中验证所有签名?
标签: python digital-signature pdftron