How to retrieve digital signature information (name, date, ...) with ItextSharp
10,927
Short example:
StringBuilder sb = new StringBuilder();
PdfReader reader = new PdfReader(pdf);
AcroFields af = reader.AcroFields;
ArrayList names = af.GetSignatureNames();
for (int i = 0; i < names.Count; ++i) {
String name = (string)names[i];
PdfPKCS7 pk = af.VerifySignature(name);
sb.AppendFormat("Signature field name: {0}\n", name);
sb.AppendFormat("Signature signer name: {0}\n", pk.SignName);
sb.AppendFormat("Signature date: {0}\n", pk.SignDate);
sb.AppendFormat("Signature country: {0}\n",
PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("C")
);
sb.AppendFormat("Signature organization: {0}\n",
PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("O")
);
sb.AppendFormat("Signature unit: {0}\n",
PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("OU")
);
}
Author by
Fbo
Updated on June 04, 2022Comments
-
Fbo almost 2 years
I have a PDF which has been signed by 2 people (by Eid).
I'm trying to retrieve this information but I'm unable so far.
This is what I have so far:
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string workingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string inputFile = Path.Combine(workingFolder, "Tax Return.pdf"); PdfReader reader = new PdfReader(inputFile); Console.ReadLine(); } } }
If I inspect 'reader' during runtime I can see that AcroForm has 2 Fields that point to the signatures but I'm unable to see any specific information about these signatures.