Yes, the procedure is different and I have to make an "How to sign" in C#.
Here's an example to get you going:

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();
}

----- Original Message ----- 
From: "Matthew Wagner" <[EMAIL PROTECTED]>
To: <itext-questions@lists.sourceforge.net>
Sent: Thursday, August 11, 2005 8:31 PM
Subject: [iText-questions] iTextSharp


> Is there a C# alternative to java.security.KeyStore? I'm trying to sign a
pdf
> with iTextSharp and am having trouble getting past this part.
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to