Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

java program to add digital signature into a pdf file

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

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





 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Generate key using the following command

keytool -genkey -keypass key_pwd -keystore test.pfx -storepass store_pwd -storetype PKCS12 -alias key_alias
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic