Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 PDF数字签名禁用CRL_C# 4.0_Itext - Fatal编程技术网

C# 4.0 PDF数字签名禁用CRL

C# 4.0 PDF数字签名禁用CRL,c#-4.0,itext,C# 4.0,Itext,我正在使用itextsharp.dll编写pdf签名示例。数字签名在usb设备上 它工作得很好,唯一的问题是有时签名会完全停止几个小时 我发现签名过程会转到数字发行人站点,以使CRL嵌入到签名文档中,将其大小从100kb增加到1300kb+,并且由于从发行人站点获取CRL,因此签名文档的速度非常慢 但是,如果我禁用internet,文件的签名速度会非常快,文件大小只会增加5-10kb 因此,我的问题恰恰是,我如何指示签名过程不要在线获取CRL n,只需在原始文档中以较小的大小增加快速签名文档即可

我正在使用itextsharp.dll编写pdf签名示例。数字签名在usb设备上

它工作得很好,唯一的问题是有时签名会完全停止几个小时

我发现签名过程会转到数字发行人站点,以使CRL嵌入到签名文档中,将其大小从100kb增加到1300kb+,并且由于从发行人站点获取CRL,因此签名文档的速度非常慢

但是,如果我禁用internet,文件的签名速度会非常快,文件大小只会增加5-10kb

因此,我的问题恰恰是,我如何指示签名过程不要在线获取CRL n,只需在原始文档中以较小的大小增加快速签名文档即可

public void Sign(ICollection<X509Certificate> chain, X509Certificate2 pk,
                    String digestAlgorithm, CryptoStandard subfilter,
                    String reason, String location,
                    int estimatedSize)
    {

        IList<ICrlClient> crlList = new List<ICrlClient>();
        crlList.Add(new CrlClientOnline(chain));


        // Creating the reader and the stamper
        PdfReader reader = null;
        PdfStamper stamper = null;
        FileStream os = null;
        //int noofpdfs = 0;
        var watch = Stopwatch.StartNew();
        try
        {
            string[] srcfiles;
            if (lblSplitedFilePath.Text.Equals("Split By Page Directory"))
                srcfiles = Directory.GetFiles(tbsrcpath.Text, "*.pdf");
            else
                if (tbsrcpath.Text.ToUpper().Contains(@"\SPLIT"))
                srcfiles = Directory.GetFiles(tbsrcpath.Text, "*.pdf");
            else
                srcfiles = Directory.GetFiles(tbsrcpath.Text + @"\split\", "*.pdf");

            //int noofpdfs = srcfilePaths.Count();
            for (int i = 0; i < srcfiles.Count(); i++)
            {
                // Get FileName
                lblOutputFile.Text = tbtgtpath.Text + @"\" + Path.GetFileName(srcfiles[i]);
                lblOutputFile.Refresh();
                os = new FileStream(lblOutputFile.Text, FileMode.Create);
                reader = new PdfReader(srcfiles[i]);
                iTextSharp.text.Rectangle pdfbox = reader.GetPageSize(1);
                stamper = PdfStamper.CreateSignature(reader, os, '\0');
                // Creating the appearance
                PdfSignatureAppearance appearance = stamper.SignatureAppearance;
                if (!string.IsNullOrWhiteSpace(tbContact.Text))
                {
                    appearance.ReasonCaption = "Contact:";
                    appearance.Reason = tbContact.Text;// reason;
                }
                appearance.Location = location;


                //Adding Image to Sign
                if (cbAddImageSign.Checked)
                {
                    var image = iTextSharp.text.Image.GetInstance(tbSignImage.Text);
                    appearance.Acro6Layers = true;
                    appearance.SignatureGraphic = image;
                    appearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION;
                }


                int llx, lly, urx, ury;
                int.TryParse(Tbllx.Text, out llx);
                int.TryParse(tblly.Text, out lly);
                int.TryParse(tburx.Text, out urx);
                int.TryParse(tbury.Text, out ury);
                pdfSigning.Properties.Settings.Default.llx = llx;
                pdfSigning.Properties.Settings.Default.lly = lly;
                pdfSigning.Properties.Settings.Default.urx = urx;
                pdfSigning.Properties.Settings.Default.ury = ury;
                appearance.SetVisibleSignature(new iTextSharp.text.Rectangle(llx, lly, urx, ury), 1, "sig");


                //Add Water mark
                if (!lblWaterMarkImagePath.Text.Equals("Pdf Water Mark Image Path"))
                {
                    var wmimage = iTextSharp.text.Image.GetInstance(lblWaterMarkImagePath.Text);
                    wmimage.SetAbsolutePosition(0, 0);
                    wmimage.ScaleToFit(100, 100);
                    for (var j = 0; j < reader.NumberOfPages; j++)
                    {
                        var content = stamper.GetUnderContent(j + 1);
                        content.AddImage(wmimage);
                    }
                }
                //appearance.setRenderingMode(PdfSignatureAppearance.RenderingMode.GRAPHIC);
                // Creating the signature

                try
                {
                    IExternalSignature pks = new X509Certificate2Signature(pk, digestAlgorithm);
                    MakeSignature.SignDetached(appearance, pks, chain, crlList, null, null, estimatedSize,
                                               subfilter);

                }
                catch (CryptographicException ex)
                {

                    MessageBox.Show(ex.ToString());
                }

                //noofpdfs++;
                if (cbPrintOnSign.Checked)
                {
                    switch (tbPrintMethod.Text)
                    {
                        case "2":
                            SendFileToPrinter(lblOutputFile.Text, printpdf2printer);
                            break;
                        default:
                            SendToPrinter(lblOutputFile.Text);
                            break;
                    }

                }
                if (cbDeletePdfPostSign.Checked)
                {
                    File.Delete(srcfiles[i]);
                }
                dgvPrintFiles.Rows.Add(srcfiles[i].ToString());

            }
            lblOutputFile.Text += @" Siging Over:Signed " + srcfiles.Count().ToString() + " Files";
        }
        finally
        {
            if (reader != null)
                reader.Close();
            if (stamper != null)
                stamper.Close();
            if (os != null)
                os.Close();
        }
        watch.Stop();
        var elapsedMs = watch.ElapsedMilliseconds;
        MessageBox.Show("Signing Time:" + elapsedMs / 1000 + " Second");
    }
public void Sign(ICollection chain,X509Certificate2 pk,
字符串算法,加密标准子过滤器,
字符串原因,字符串位置,
整数(估计大小)
{
IList crlList=新列表();
添加(新的CrlClientOnline(链));
//创建读卡器和压模
PdfReader reader=null;
PdfStamper压模=null;
FileStream os=null;
//int noofpdfs=0;
var watch=Stopwatch.StartNew();
尝试
{
字符串[]文件;
if(lblSplitedFilePath.Text.Equals(“按页面目录拆分”))
srcfiles=Directory.GetFiles(tbsrcpath.Text,“*.pdf”);
其他的
如果(tbsrcpath.Text.ToUpper().包含(@“\SPLIT”))
srcfiles=Directory.GetFiles(tbsrcpath.Text,“*.pdf”);
其他的
srcfiles=Directory.GetFiles(tbsrcpath.Text+@“\split\”,“*.pdf”);
//int noofpdfs=srcfilepath.Count();
对于(int i=0;i