Tim Moores wrote:It seems you're back to a point where this isn't even working for a desktop app? So the problem is not with making it work in a web app, but in getting the fundamentals right?
If you have a problem, then please describe the problem. Whatever steps you tried to follow is irrelevant (and just clutters up this thread) if you don't tell us what, specifically, the problem is, and what, specifically, you did when you encountered it. "it is giving input not an X.509 certificate" is, I'm afraid, useless as a problem description.
i have created the foobar certificate with the help of itext tutorial but how to import root certificate and how to certify foobar certificate from certifying authority..and then how to use keys in the certificate for digital signature in pdf ......i am pasting code here please tell me the error so that i can solve my problem ...i dont know but it may be the problem related to pkcs format..
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.*;
import org.bouncycastle.jce.provider.symmetric.SEED;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.DocumentException;
public class digital extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
private static final long serialVersionUID = 1L;
KeyStore ks= null;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Document document = new Document();
try {
try {
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("/resources/a.pdf"));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ks = KeyStore.getInstance(KeyStore.getDefaultType());
} catch (KeyStoreException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
}
try {
String f = getServletContext().getRealPath("/resources/.keystore");
ks.load(
new FileInputStream(f),"abcdef".toCharArray());
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
} catch (CertificateException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
}
PrivateKey key= null;
try {
key = (PrivateKey) ks.getKey("foobar", "abcdef".toCharArray());
} catch (KeyStoreException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnrecoverableKeyException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
}
Certificate[] chain= null;
try {
chain = ks.getCertificateChain("foobar");
} catch (KeyStoreException ex) {
Logger.getLogger(SEED.class.getName()).log(Level.SEVERE, null, ex);
}
PdfReader reader = new PdfReader(getServletContext().getRealPath("/resources/a.pdf"));
FileOutputStream os = new FileOutputStream("/resources/Signed.pdf");
PdfStamper stamper = null;
try {
stamper = PdfStamper.createSignature(reader, os, '\0');
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCrypto(key, chain, null,PdfSignatureAppearance.SELF_SIGNED);
appearance.setReason("It's personal.");
appearance.setLocation("Foobar");
appearance.setVisibleSignature(new Rectangle(160,732,232,780), 1, null);
try {
stamper.close();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
document.close();
}
}
and i am getting following error.
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.io.FileNotFoundException: \resources\a.pdf (The system cannot find the path specified)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(Unknown Source)
java.io.FileOutputStream.<init>(Unknown Source)
archana.digital.doGet(digital.java:44)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.16
In
tomcat there is no full stack trace .log folder is empty