Hi Mike,
I've just finished the same endeavor over de past few days. Here is a piece of
code that allowed me to sign a pdf.
It's not C#, but I hope it will guide you towards a C# implementation:
---
import com.chrysalisits.cryptox.*;
import com.chrysalisits.crypto.*;
import java.io.*;
import java.security.*;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfSignatureAppearance;
import java.util.Date;
public class SignPDF {
private static LunaTokenManager hsm = LunaTokenManager.getInstance();
private static final String PASSWORD = "<ENTER YOUR PARTITION PASSWORD HERE>";
public static void main(String[] args) {
try {
hsm.Login(PASSWORD);
KeyStore ks = KeyStore.getInstance("Luna");
ks.load(null, null);
PrivateKey key = (PrivateKey)ks.getKey("<ENTER LABEL OF PRIVATE KEY
HERE>", null);
// we're using a certificate by Quovadis and have to add the chain
manually
// because Luna doesn't provide an implementation for
getCertificateChain()
java.security.cert.Certificate[] chain = new
java.security.cert.Certificate[3];
chain[0] = ks.getCertificate("<ENTER YOUR CERTIFICATE LABEL HERE>");
chain[1] = ks.getCertificate("QuoVadis EU Issuing Certification
Authority");
chain[2] = ks.getCertificate("QuoVadis Root Certification Authority");
PdfReader src = new PdfReader("<ENTER INPUT FILE HERE>");
FileOutputStream trg = new FileOutputStream("<ENTER OUTPUT FILE HERE>");
PdfStamper stp = PdfStamper.createSignature(src, trg, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto( key, chain, null, PdfSignatureAppearance.WINCER_SIGNED );
stp.close();
hsm.Logout();
} catch( Exception e ) { System.out.println( e ); }
}
}
--
compile:
javac -cp
iText-2.1.7.jar:bcprov-jdk16-145.jar:/usr/lunasa/jsp/lib/LunaJCASP.jar:/usr/lunasa/jsp/lib/LunaJCESP.jar:.
SignPDF.java
run:
java -Djava.library.path=/usr/lunasa/jsp/lib/ -cp
iText-2.1.7.jar:bcprov-jdk16-145.jar:/usr/lunasa/jsp/lib/LunaJCASP.jar:/usr/lunasa/jsp/lib/LunaJCESP.jar:.
SignPDF
Hope it helps you,
regards,
Christophe VG
On 23 Sep 2010, at 17:32, Mike Chynoweth wrote:
> After several days of working with the “signing” examples found at:
> http://itextpdf.sourceforge.net/howtosign.html, I still have not been able to
> successfully sign a document using a Luna SA HSM device.
>
> I’ve focused on the “External Signing” examples on the previously mentioned
> “howtosign” page and I’ve read dozens of posts (including this one:
> http://itext-general.2136553.n4.nabble.com/Luna-SA-Integration-with-iText-td2162123.html#a2162127),
> but have not been able to figure out exactly what needs to be done in C# to
> sign a document using the Luna SA device.
>
> Does anyone have any experience getting PDF signing working in this type of
> scenario? If so I would appreciate any advice/examples/pointers you can
> offer. Thanks in advance.
> Mike Chynoweth
> Software Engineer
> AssureSign, LLC
> 220 East Central Parkway, Suite 3000
> Altamonte Springs, FL 32701
> Office: 407.670.0400 Ext. 257
> Fax: 407.774.3388
> Email: [email protected]
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev_______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.itextpdf.com/book/
> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
> You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/