我正在使用iTextsharp 5.5.13.0在C#项目中使用智能卡(X509Certificate2)签署pdf文件。标记的标记过程很好,但签名所需的时间远远多于此过程的早期版本(iTextsharp 4.1.2.0)。
以前,选择证书和签名过程之间的间隔不超过10秒,现在需要的时间超过两倍。
这是pdf签名的代码。我还附上了签名所需时间的图像。我可以做些什么来缩短签名时间?
public static void SignHashed(string Source, string Target, X509Certificate2 Certificate, string Reason, string Location, bool AddTimeStamp, string strTSA)
{
X509CertificateParser objCP = new X509CertificateParser();
X509Certificate[] objChain = new X509Certificate[] { objCP.ReadCertificate(Certificate.RawData) };
IList<ICrlClient> crlList = new List<ICrlClient>();
crlList.Add(new CrlClientOnline(objChain));
PdfReader objReader = new PdfReader(Source);
PdfStamper objStamper = PdfStamper.CreateSignature(objReader, new FileStream(Target, FileMode.Create), '\0', null, true);
int pageNumber = objReader.NumberOfPages;
ITSAClient tsaClient = null;
IOcspClient ocspClient = null;
if (AddTimeStamp)
{
OcspVerifier ocspVerifier = new OcspVerifier(null, null);
ocspClient = new OcspClientBouncyCastle(ocspVerifier);
tsaClient = new TSAClientBouncyCastle(strTSA);
}
PdfSignatureAppearance signatureAppearance = objStamper.SignatureAppearance;
signatureAppearance.Reason = Reason;
signatureAppearance.Location = Location;
signatureAppearance.Acro6Layers = true;
signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.NAME_AND_DESCRIPTION;
signatureAppearance.SetVisibleSignature(new Rectangle(50, 10, 200, 66), pageNumber, null);
IExternalSignature externalSignature = new X509Certificate2Signature(Certificate, "SHA-1");
// this process take to much time
MakeSignature.SignDetached(signatureAppearance, externalSignature, objChain, crlList, ocspClient, tsaClient, 0, CryptoStandard.CMS);
if (objReader != null)
{
objReader.Close();
}
if (objStamper != null)
{
objStamper.Close();
}
}