You'll have to try a bit harder to explain your problem.
----- Original Message -----
From: "Dan Phillips" <[EMAIL PROTECTED]>
To: "'Paulo Soares'" <[EMAIL PROTECTED]>
Sent: Tuesday, November 29, 2005 7:29 PM
Subject: RE: [iText-questions] itextsharp with an external hash and
signature in Windows Certificate Mode
Paulo,
Thank you for the response.
We have managed to sign the pdf sucessfully using your example but we are
now trying to generate and external hash and use that to sign the document
as outlined in the howtosign.html examples available from the sourceForge
site. Our problem is that we are unable to past the MessageDigest object
creation in the code. Any ideas?
An example with an external hash and signature in Windows Certificate Mode
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("my_private_key.pfx"),
"my_password".toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias,
"my_password".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader("original.pdf");
FileOutputStream fout = new FileOutputStream("signed.pdf");
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.setReason("I'm the author");
sap.setLocation("Lisbon");
// comment next line to have an invisible signature
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
sap.setExternalDigest(new byte[128], new byte[20], "RSA");
sap.preClose();
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
byte buf[] = new byte[8192];
int n;
InputStream inp = sap.getRangeStream();
while ((n = inp.read(buf)) > 0) {
messageDigest.update(buf, 0, n);
}
byte hash[] = messageDigest.digest();
PdfSigGenericPKCS sg = sap.getSigStandard();
PdfLiteral slit = (PdfLiteral)sg.get(PdfName.CONTENTS);
byte[] outc = new byte[(slit.getPosLength() - 2) / 2];
PdfPKCS7 sig = sg.getSigner();
Signature sign = Signature.getInstance("SHA1withRSA");
sign.initSign(key);
sign.update(hash);
sig.setExternalDigest(sign.sign(), hash, "RSA");
PdfDictionary dic = new PdfDictionary();
byte[] ssig = sig.getEncodedPKCS7();
System.arraycopy(ssig, 0, outc, 0, ssig.length);
dic.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));
sap.close(dic);
Regards,
Dan Phillips
-----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 29, 2005 2:21 PM
To: Dan Phillips; [email protected]
Subject: Re: [iText-questions] itextsharp with an external hash and
signature in Windows Certificate Mode
See
http://article.gmane.org/gmane.comp.windows.dotnet.itextsharp.general/12
----- Original Message -----
From: "Dan Phillips" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, November 29, 2005 6:34 PM
Subject: [iText-questions] itextsharp with an external hash and signature
in
Windows Certificate Mode
I am trying to port over the example itext java code for an external
signature to use the itextsharp classes. I am having a problem using
the declaring and using the MessageDigest class. We have searched the
references for the org.bouncycastle and itext references adn are unable
to find a compatible class definition.
Is it possible to use itextsharp itextsharp with an external hash and
signature in Windows Certificate Mode ?
TIA
Dan Phillips
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions