RE: Help Required: iText & C# -Urgent

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

RE: Help Required: iText & C# -Urgent

Paulo Soares
From another answer:

Things are done differently and I didn't have to time update the docs.
Try this:

To sign (note that for the moment CRLs are not supported):
 
using org.bouncycastle.pkcs;
using org.bouncycastle.crypto;
using org.bouncycastle.x509;
using iTextSharp.text;
using iTextSharp.text.pdf;
 
string alias = null;
PKCS12Store pk12 = new PKCS12Store(new FileStream("c:\\the_key.pfx",
FileMode.Open, FileAccess.Read), "password".ToCharArray()); IEnumerator
i = pk12.aliases(); while (i.MoveNext()) {

    alias = ((string)i.Current);
    if (pk12.isKeyEntry(alias))
        break;
}
AsymmetricKeyParameter akp = pk12.getKey(alias).getKey();
X509CertificateEntry[] ce = pk12.getCertificateChain(alias);
X509Certificate[] chain = new X509Certificate[ce.Length]; for (int k =
0; k < ce.Length; ++k)

    chain[k] = ce[k].getCertificate();
PdfReader reader = new PdfReader("input.pdf"); PdfStamper st =
PdfStamper.CreateSignature(reader, new FileStream("output.pdf",
FileMode.Create, FileAccess.Write), '\0'); PdfSignatureAppearance sap =
st.SignatureAppearance; sap.SetCrypto(akp, chain, null,
PdfSignatureAppearance.WINCER_SIGNED);

sap.Reason = "My Signature";
sap.Location = "Universe";
sap.SetVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
st.Close();
 
 
To verify the only problem is where to get the certificates.
 
To get the certificates from the system using WSE:
 
using wsex = Microsoft.Web.Services.Security.X509;
 
wsex.X509CertificateStore store = new
wsex.X509CertificateStore(wsex.X509CertificateStore.StoreProvider.System
, wsex.X509CertificateStore.StoreLocation.LocalMachine,
wsex.X509CertificateStore.RootStore);

store.Open();
wsex.X509CertificateCollection c = store.Certificates; foreach
(wsex.X509Certificate cert in c) {
    X509Certificate c2 = new X509Certificate(cert.GetRawCertData());
}
 
 
To get the certificates from some PKCS#7:
 
X509CertificateParser p = new X509CertificateParser(new
FileStream("filecertexp.p7b", FileMode.Open, FileAccess.Read));
X509Certificate x = p.ReadCertificate(); while (x != null) {

    x = p.ReadCertificate();
}  

Have also a look at http://itextpdf.sourceforge.net/howtosign.html.
Please reply to the mailing list, I won't answer directly addressed
mail, you got lucky this time.


> -----Original Message-----
> From: Nobody [mailto:[hidden email]] On
> Behalf Of khan
> Sent: Thursday, September 29, 2005 8:43 AM
> To: [hidden email]
> Subject: Help Required: iText & C# -Urgent
>
>
> Message body follows:
>
> Hello
>
> Questions regarding iText with reference to  C#
> 1-How to find/read/identify a signature field/s in a PDF file and
> determinig its state i.e signed/unsigned?
> 2-How to distinguish between different signature fields in a
> same PDF file ?
>
> Kindly send me code in c#  in the following address
> [hidden email]
>
> Thanking you in advance
> waiting
> fawad
>
>
> --
> This message has been sent to you, a registered SourceForge.net user,
> by another site user, through the SourceForge.net site.  This message
> has been delivered to your SourceForge.net mail alias.  You may reply
> to this message using the "Reply" feature of your email client, or
> using the messaging facility of SourceForge.net at:
> https://sourceforge.net/sendmessage.php?touser=1353700
>
>


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions