Hello.

I have made a program related to PDF digital signing with iTextSharp.

I already read "How to sign a PDF using iText and iTextSharp" tutorial
and some postings in the mailing list.

But, I could not succeed in inserting digital signature at existing PDF files.


My test codes are as followings (it was from the C# sample of iText
mailing list.);

-------------------


Private Sub Test1()

       Dim [alias] As String = "Dark"
       Dim pk12 As New Pkcs12Store(New FileStream("myTestKey.pfx",
FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
"1234".ToCharArray())

       'Below codes were commented because an invalid Casting error occurred.
       '-------------------
       'Dim i As IEnumerator = pk12.Aliases()  '-> generate invalid cast error

       'While i.MoveNext()
       '    [alias] = CStr(i.Current)
       '    If pk12.IsKeyEntry([alias]) Then
       '        Exit While
       '    End If
       'End While
       '---------------------

       Dim akp As AsymmetricKeyParameter = pk12.GetKey([alias]).Key
       Dim ce As X509CertificateEntry() = pk12.GetCertificateChain([alias])
       Dim chain(ce.Length) As X509Certificate
       Dim k As Integer

       While k < ce.Length
           chain(k) = ce(k).Certificate
           k += 1
       End While

       Dim reader As New PdfReader("unsigned_signature_field.pdf")

       Dim st As PdfStamper = PdfStamper.CreateSignature(reader, New
FileStream("output.pdf", FileMode.Create, FileAccess.Write), "\0",
vbNullString, True)
       Dim sap As PdfSignatureAppearance = st.SignatureAppearance

       sap.SetCrypto(akp, chain, Nothing,
PdfSignatureAppearance.WINCER _SIGNED)
       sap.Reason = "My Signature"
       sap.Location = "Universe"
       sap.SetVisibleSignature("foobarsig")

       st.Close()         '-> Null reference exception error is occurred.

   End Sub

----------------------------------

An invalid casting error and a null reference exception occurred.

I added comments wherer error was generated in the above codes.



My testing environments were as this;

1. I used the latest iTextSharp and BouncyCastle.

2. My test program was compiled with VS 2003.

3. I made a pfx file using KeyTool GUI 1.7 and an input file using
Acrobat 8 Pro.



I attached my full testing codes, testing key and input files.



By the way, could you tell me how to sign for self signed mode with iTextSharp?

I do now know how to sign although I already read related postings
because most of them were for JDK; Keystore does not exist at .NET
framework.



If you could take a few minutes to answer my questions, I would really
appreciate it.

Thank you in advance for your help.


Best regards,

S. H. Park

Attachment: DigitalSigTest.rar
Description: Binary data

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to