将pkcs7签名字节嵌入到PDF文档中

时间:2019-07-17 07:11:09

标签: c# pdf itext7

我正在使用itext7进行pdf操作。我从签名服务器获取了pkcs7签名字节,我不得不将这些pkcs7签名字节作为不可见的签名嵌入到PDF文档中。

当前,我正在尝试使用pdf acro格式添加pkcs7签名字节,但未成功。 这是我的代码段:

        Stream readerStream = new MemoryStream(_latestDocumentBytes);
        PdfReader pdfReader = new PdfReader(readerStream);

        using (Stream stream = new MemoryStream())
        {
            PdfDocument pdfDocument = new PdfDocument(pdfReader, new PdfWriter(stream));
            PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDocument, true);

            acroForm.Put(PdfName.Contents, new PdfString(pdfSignatureBytes).SetHexWriting(true));
            acroForm.MakeIndirect(pdfDocument);



            pdfDocument.Close();
            _latestDocumentBytes = ((MemoryStream)stream).ToArray();
        }

0 个答案:

没有答案