gpt4 book ai didi

c# - 签署 pdf 文件

转载 作者:行者123 更新时间:2023-11-30 20:51:39 35 4
gpt4 key购买 nike

目前我正在升级我的旧应用程序,它是使用 itextsharp 5.0.0 完成的到 5.4.5(最新)...但是我在获取等效代码时遇到了问题

PdfSignatureAppearance.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.SELF_SIGNED);

谁能帮我解决这个问题?

提前致谢...

最佳答案

我使用 5.5 版本的 iTextSharp 签署 PDF 文档。下面是示例代码。

        // Set the reader (PdfReader) and output (Stream) first
PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0');

PdfSignatureAppearance signatureAppearance = stamper.SignatureAppearance;
signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION;
signatureAppearance.Reason = "I love signing";
signatureAppearance.LocationCaption = "";
signatureAppearance.SignatureGraphic = Image.GetInstance(this.imageFolderPath + "sign.png");

signatureAppearance.SetVisibleSignature(
new Rectangle(100, 100, 300, 200),
reader.NumberOfPages,
"Signature");

// Get certificate from store, here I am reading file
X509Certificate2 cert = new X509Certificate2(certFile, certPassword);
var keyPair = DotNetUtils.GetKeyPair(cert.PrivateKey).Private;
BcX509.X509Certificate bcCert = DotNetUtils.FromX509Certificate(cert);
var chain = new List<BcX509.X509Certificate> { bcCert };
IExternalSignature signature = new PrivateKeySignature(keyPair, "SHA-256");

MakeSignature.SignDetached(signatureAppearance, signature, chain, null, null, null, 0, CryptoStandard.CMS);

stamper.Close();

关于c# - 签署 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21474649/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com