aspose file tools*
The moose likes Java in General and the fly likes java program to add digital signature into a pdf file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java program to add digital signature into a pdf file" Watch "java program to add digital signature into a pdf file" New topic
Author

java program to add digital signature into a pdf file

pavithra murthy
Ranch Hand

Joined: Feb 06, 2009
Posts: 56
dear all ,

1. i need to write a java program for adding digital signature to a page in a pdf file .

* i have to use the profile created by the user where private key ,certificate and public key are stored .
* i need to use the signature found in that profile . may be i have to extract it and add it to the pdf page .

could anyone please help me out regarding this because have not worked earlier on this .

what are the requirements and how to go about it .

thank you .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
The iText library can sign PDFs; see How to sign a PDF using iText for details. I don't think it's possible to sign individual pages, though.
pavithra murthy
Ranch Hand

Joined: Feb 06, 2009
Posts: 56
hello friend ,

i am encountering this error when i compile this program ..i have used itext.jar file

pdfsign1.java:27: reference to Certificate is ambiguous, both class java.securit
y.cert.Certificate in java.security.cert and class java.security.Certificate in
java.security match
Certificate[] chain = ks.getCertificateChain(alias);
^
1 error


could you please help me out ..

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
Both the java.security and the java.security.cert package have a "Certificate" class/interface. You can only import one with a wildcard. In this case, you want the one in java.security.cert.

catch (Exception e) {}

That's a bad idea. How a will you know what's going wrong with the code?
pavithra murthy
Ranch Hand

Joined: Feb 06, 2009
Posts: 56
hello friend ,

i have written a java code for adding digital signature to pdf file .

i am encountering an exception when the program is run .

C:\excel>java pdfsign1
java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big.
at sun.security.util.DerInputStream.getLength(Unknown Source)
at sun.security.util.DerValue.init(Unknown Source)
at sun.security.util.DerValue.<init>(Unknown Source)
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(Unknown Sou
rce)
at java.security.KeyStore.load(Unknown Source)
at pdfsign1.main(pdfsign1.java:23)

i am creating a key with name "my_private_key.pfx" specified in the program using the command
keytool -genkey -keyalg RSA -alias myname -keypass password -keystore my_private_key.pfx

pavithra murthy
Ranch Hand

Joined: Feb 06, 2009
Posts: 56
hello friends ,

i have written a code using jPDFProcess.jar file . there are two classes SignDocument and ExportFields.java
exportfields is super class
signdocument is subclass

i am creating a key sample PKCS#12 file using the command

keytool -genkey -keyalg RSA -alias myname -keypass store_pwd -keystore keystore.pfx


both classes are compiling fine but while running i am getting the same following exceptions
could anyone please help me out
-------------------------------------------------
Exception in thread "main" java.lang.IncompatibleClassChangeError: class com.qop
pa.pdfProcess.PDFDocument has interface com.qoppa.pdfViewer.g.k as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

-----------------------------------------





Rao Jr
Greenhorn

Joined: Jun 08, 2009
Posts: 1

Generate key using the following command

keytool -genkey -keypass key_pwd -keystore test.pfx -storepass store_pwd -storetype PKCS12 -alias key_alias
 
wood burning stoves
 
subject: java program to add digital signature into a pdf file