2014-01-31 313 views
1

目前我升級我這是使用iTextSharp的5.0.0至5.4.5(最新)做舊的應用程序......但我在獲得同等代碼簽名PDF文檔

PdfSignatureAppearance.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.SELF_SIGNED); 

問題有誰能幫我解決這個問題嗎?

在此先感謝...

+0

簽名API(至少是您期望使用的最高級別)已經發生了一些變化。您可能需要閱讀[PDF文檔的數字簽名](http://itextpdf.com/book/digitalsignatures),*由Bruno Lowagie(iText Software)*編寫的白皮書*與iText(Sharp)簽署。其中的代碼示例使用Java,但C#版本也可用。 – mkl

+0

你可以給我提供C#鏈接嗎? –

+0

它們至少可以在[tutorial](http://svn.code.sf.net/p/itextsharp/code/tutorial)中的subversion版本庫中找到;不過,我不知道是否有任何美化版本。 – mkl

回答

3

我籤使用5.5版本的iTextSharp的的PDF文檔。 以下是示例代碼。

 // Set the reader (PdfReader) and output (Stream) first 
     PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0'); 

     PdfSignatureAppearance signatureAppearance = stamper.SignatureAppearance; 
     signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION; 
     signatureAppearance.Reason = "I love signing"; 
     signatureAppearance.LocationCaption = ""; 
     signatureAppearance.SignatureGraphic = Image.GetInstance(this.imageFolderPath + "sign.png"); 

     signatureAppearance.SetVisibleSignature(
      new Rectangle(100, 100, 300, 200), 
      reader.NumberOfPages, 
      "Signature"); 

     // Get certificate from store, here I am reading file 
     X509Certificate2 cert = new X509Certificate2(certFile, certPassword); 
     var keyPair = DotNetUtils.GetKeyPair(cert.PrivateKey).Private; 
     BcX509.X509Certificate bcCert = DotNetUtils.FromX509Certificate(cert); 
     var chain = new List<BcX509.X509Certificate> { bcCert }; 
     IExternalSignature signature = new PrivateKeySignature(keyPair, "SHA-256"); 

     MakeSignature.SignDetached(signatureAppearance, signature, chain, null, null, null, 0, CryptoStandard.CMS); 

     stamper.Close();