这是我的代码:
PdfReader reader = new PdfReader(file);
AcroFields af = reader.AcroFields;
List<string> names = af.GetSignatureNames();
for (int i = 0; i < names.Count; ++i)
{
// it is working fine
string name = (string)names[i];
iTextSharp.text.pdf.security.PdfPKCS7 pk = af.VerifySignature(name);
Console.WriteLine();
Console.WriteLine(String.Format("Podepsal: {0}", pk.SignName));
Console.WriteLine(String.Format("Datum: {0}", pk.SignDate));
Console.WriteLine(String.Format("Platnost od: {0}", pk.SigningCertificate.NotBefore));
Console.WriteLine(String.Format("Platnost do: {0}", pk.SigningCertificate.NotAfter));
// here I need to help
Org.BouncyCastle.Tsp.TimeStampToken tts = pk.TimeStampToken;
string s = tts.TimeStampInfo.Tsa.Name.ToString();
// this line returns null
DateTime dt = tts.SignerID.Certificate.NotAfter;
}
以下是pdf样本http://www.filedropper.com/sample
谢谢!
答案 0 :(得分:1)
与您在af.VerifySignature
通话期间已通过iText验证的基本签名相比,尚未分析签名时间戳。特别是尚未查找实际的TSA证书。
因此,您首先必须确定相关证书。通常它包含在时间戳带来的证书集合中,因此在下面我假设它存在(它是在您的示例文件的情况下)。我们通过发行人和序列号查找,然后我们用它验证时间戳,以确保它是正确的证书,而不是假的。此后,您可以根据需要检查证书。
// Define a selector matching issuer and serial number
X509CertStoreSelector selector = new X509CertStoreSelector();
selector.Issuer = tts.SignerID.Issuer;
selector.SerialNumber = tts.SignerID.SerialNumber;
// Retrieve the matching certificates from the time stamp certificate collection
System.Collections.ICollection certs = tts.GetCertificates("COLLECTION").GetMatches(selector);
// Assuming at most one match, retrieve this matching certificate
IEnumerator enumCerts = certs.GetEnumerator();
if (enumCerts.MoveNext())
{
X509Certificate cert = (X509Certificate)enumCerts.Current;
// Verify that this is the correct certificate by verifying the time stamp token
tts.Validate(cert);
// Extracting information from the now verified tsa certificate
Console.WriteLine(String.Format("Not before: {0}", cert.NotBefore));
Console.WriteLine(String.Format("Not after: {0}", cert.NotAfter));
}