阅读xml PKCS7响应并嵌入到pdf C#中

时间:2019-07-16 06:38:25

标签: c# asp.net digital-signature pkcs#7

具有xml响应,该响应具有PKCS7格式的随机字符串。我需要将PKCS7字符串嵌入到pdf中。

What is the step to do the same in asp.net c#

查找输入xml文件Input XML

输出 数字签名pdf

尝试过以下提到的代码

string str = "which contains pkcs7 string";
    string file = @"D:\Sourcefile.pdf";
    string targetDir = @"D:\";
    string fileName = "targetFile.pdf";
    PdfReader reader = new PdfReader(file);
    using (FileStream fout = new FileStream(targetDir + fileName, FileMode.Create))
    {
            PdfStamper stp = PdfStamper.CreateSignature(reader, fout, '\0', null, true);
            PdfSignatureAppearance pdfSignatureAppearance = stp.SignatureAppearance;
            byte[] sigbytes = Convert.FromBase64String(str);
            int contentEstimated = 8192 * 2;
            byte[] paddedSig = new byte[contentEstimated];
            Array.Copy(sigbytes, 0, paddedSig, 0, sigbytes.Length);
            PdfDictionary dic2 = new PdfDictionary();
            dic2.Put(PdfName.CONTENTS, new PdfString(paddedSig).SetHexWriting(true));
            Dictionary<PdfName, int> exc = new Dictionary<PdfName, int>();
            exc[PdfName.CONTENTS] = contentEstimated * 2 + 2;
            pdfSignatureAppearance.PreClose(exc);
            pdfSignatureAppearance.Close(dic2);
        }

但是收到错误消息“未知过滤器:{1}”

0 个答案:

没有答案