如何使用itextsharp签名Pdf? [英] How can i sign a Pdf with itextsharp?

查看:124
本文介绍了如何使用itextsharp签名Pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在尝试使用C#编程签名Pdf,但是我遇到了一些问题.
创建pdf时,我想签字,但文档完成后不签字.

有什么想法吗?.

感谢您的关注.

Hi guys!!

I''m trying to sign a Pdf Programatically with c#, but i''m having some problems.
When i''m creating the pdf i want to put my sign, but no when the document is already done.

Any idea??.

Thanks for your attention.

推荐答案

KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("my_private_key.pfx"), "my_password".toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader("original.pdf");
FileOutputStream fout = new FileOutputStream("signed.pdf");
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.setReason("I'm the author");
sap.setLocation("Lisbon");
// comment next line to have an invisible signature
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
stp.close()


如果您只是通过Google搜索"iTextSharp数字签名",就很容易找到.
阅读 [ ^ ] ...
Easily found if you just Googled for "iTextSharp digital signature".

Read[^]...


感谢大家.

我看到了相同的示例,但我有点困惑.

与此相关的

KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("my_private_key.pfx"),"my_password" .toCharArray());
字符串别名=(String)ks.aliases().nextElement();
私钥=(PrivateKey)ks.getKey(alias,"my_password" .toCharArray());
Certificate []链= ks.getCertificateChain(alias);

你能给我解释一下吗?
我不能使用KeyStore.使用哪个指令?
thanks all of you.

I saw the same example but i''m a bit confused.

Particullary with this

KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("my_private_key.pfx"), "my_password".toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);

Can you explain me a bit??
I can''t use KeyStore. Which directive is using??


这篇关于如何使用itextsharp签名Pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆