![](/img/trans.png)
[英]Determining if a file has a digital signature in c# without actually verifying the signature
[英]Determining if a pdf file has a digital signature in c# without verifying the signature
有没有办法检查PDF文件是否有数字签名?
免费的Spire.PDF库提供了无需验证即可检查PDF文件是否具有数字签名的功能。 您可以从NuGet软件包管理器中获取Free Spire.PDF dll,并参考以下代码。
//Load PDF file
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Input.pdf");
//Gets the loaded form in the PDF file
PdfFormWidget form = pdf.Form as PdfFormWidget;
//Determine if there is any signature field among the form fields and whether it contains digital signature
for (int i = 0; i < form.FieldsWidget.Count; i++)
{
var field = form.FieldsWidget[i] as PdfSignatureFieldWidget;
if (field != null && field.Signature != null)
{
Console.WriteLine("This form field has digital signature!");
}
}
注意:我是Spire的员工。
如果您唯一需要知道的是验证其是否已签名,您可以执行以下操作:
using (PdfReader reader = new PdfReader(documentByteArray)
{
if (reader.AcroFields.GetSignatureNames().Count > 0)
{
// something if its signed
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.