Rick
2006-01-10 07:30:15 UTC
Greetings!
First to say: I am quite new to using iTextSharp, so
perhaps the question is a bit stupid. (Sorry in
advance!)
I am trying to add a digital signature to an existing
PDF document. The input I have is
1) The filename of the PDF File
2) The System.Cryptography.X509Certificate2 to sign
with. (Windows CSP Certificate on a SmartCard in my
case.)
The function should return the signed PDF as byte
array for further handling. The code is quite as it
looks in your sample: (It's VB code though...)
Public Shared Function ComputePDFDigSigFromFile
(ByVal FileName As String, ByRef Certificate As
X509Certificate2) As Byte()
Dim PK As AsymmetricAlgorithm
Dim cert(0) As
org.bouncycastle.x509.X509Certificate
cert(0) = New
org.bouncycastle.x509.X509Certificate
(Certificate.RawData())
PK = Certificate.PrivateKey
Dim PR As New iTextSharp.text.pdf.PdfReader
(FileName)
Dim Buffer As New MemoryStream
Dim Stp As New iTextSharp.text.pdf.PdfStamper
(PR, Buffer)
Dim SigAp As
iTextSharp.text.pdf.PdfSignatureAppearance
SigAp = Stp.SignatureAppearance
SigAp.SetCrypto(PK, cert, Nothing,
iTextSharp.text.pdf.PdfSignatureAppearance.WINCER_SIGN
ED)
SigAp.Reason = "Digital signature"
SigAp.Location = "Vienna"
SigAp.SetVisibleSignature(New
iTextSharp.text.Rectangle(100, 100, 200, 200), 1,
Nothing)
Stp.Close()
Return Buffer.ToArray()
End Function
The function runs through properly, no errors, no
exceptions, no problem at all. The only problem: The
PDF generated with this code does not contain a
signature.... (At least Adobe Reader 7.0.5 does not
recognize one.)
I would appreciate any help on this matter.
thanks
Rick
First to say: I am quite new to using iTextSharp, so
perhaps the question is a bit stupid. (Sorry in
advance!)
I am trying to add a digital signature to an existing
PDF document. The input I have is
1) The filename of the PDF File
2) The System.Cryptography.X509Certificate2 to sign
with. (Windows CSP Certificate on a SmartCard in my
case.)
The function should return the signed PDF as byte
array for further handling. The code is quite as it
looks in your sample: (It's VB code though...)
Public Shared Function ComputePDFDigSigFromFile
(ByVal FileName As String, ByRef Certificate As
X509Certificate2) As Byte()
Dim PK As AsymmetricAlgorithm
Dim cert(0) As
org.bouncycastle.x509.X509Certificate
cert(0) = New
org.bouncycastle.x509.X509Certificate
(Certificate.RawData())
PK = Certificate.PrivateKey
Dim PR As New iTextSharp.text.pdf.PdfReader
(FileName)
Dim Buffer As New MemoryStream
Dim Stp As New iTextSharp.text.pdf.PdfStamper
(PR, Buffer)
Dim SigAp As
iTextSharp.text.pdf.PdfSignatureAppearance
SigAp = Stp.SignatureAppearance
SigAp.SetCrypto(PK, cert, Nothing,
iTextSharp.text.pdf.PdfSignatureAppearance.WINCER_SIGN
ED)
SigAp.Reason = "Digital signature"
SigAp.Location = "Vienna"
SigAp.SetVisibleSignature(New
iTextSharp.text.Rectangle(100, 100, 200, 200), 1,
Nothing)
Stp.Close()
Return Buffer.ToArray()
End Function
The function runs through properly, no errors, no
exceptions, no problem at all. The only problem: The
PDF generated with this code does not contain a
signature.... (At least Adobe Reader 7.0.5 does not
recognize one.)
I would appreciate any help on this matter.
thanks
Rick