Sasi Reddy

Sasi Reddy

  • NA
  • 346
  • 225.8k

Digital Signature

Jan 26 2015 5:28 AM
I created documents like pfx,pvk,cer using this below link

https://msdn.microsoft.com/en-us/library/ff699202.aspx

and i added digital signature for pdf document using below code
Public Shared Sub signPdfFile(sourceDocument As String, destinationPath As String, privateKeyStream As Stream, keyPassword As String, reason As String, location As String)
Dim pk12 As New Pkcs12Store(privateKeyStream, keyPassword.ToCharArray())
privateKeyStream.Dispose()
'then Iterate throught certificate entries to find the private key entry
Dim [alias] As String = Nothing
For Each tAlias As String In pk12.Aliases
If pk12.IsKeyEntry(tAlias) Then
[alias] = tAlias
Exit For
End If
Next
Dim pk = pk12.GetKey([alias]).Key
' reader and stamper
Dim reader As New PdfReader(sourceDocument)
Using fout As New FileStream(destinationPath, FileMode.Create, FileAccess.ReadWrite)
Using stamper As PdfStamper = PdfStamper.CreateSignature(reader, fout, ControlChars.NullChar)
' appearance
Dim appearance As PdfSignatureAppearance = stamper.SignatureAppearance
'appearance.Image = new iTextSharp.text.pdf.PdfImage();
appearance.Reason = reason
appearance.Location = location
appearance.SetVisibleSignature(New iTextSharp.text.Rectangle(20, 10, 170, 60), 1, "Icsi-Vendor")
' digital signature
Dim es As IExternalSignature = New PrivateKeySignature(pk, "SHA-256")
MakeSignature.SignDetached(appearance, es, New Org.BouncyCastle.X509.X509Certificate() {pk12.GetCertificate([alias]).Certificate}, Nothing, Nothing, Nothing, _
0, CryptoStandard.CMS)
stamper.Close()
End Using
End Using
End Sub
 
after that  i need to verify digital signature while opening how to do that?..please tell me?