Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everybody;
I installs a digital certificate from globalsign in my smartphone.I wants to use it for signing a PDF documents but i don't know how to exploit it in my android application to do my purpose .There is someone who know how to do it and thanks.
Posted
Updated 12-May-15 13:00pm
v2

1 solution

I tried hard to solve the problem ,i found this code but they are a missing thing that i don't know how to get the directory of my certificate.


Java
public static final boolean signPdf()
			throws IOException, DocumentException, Exception
	{
		
		String fileKey          = "???" ;
			String fileKeyPassword  = "MyPassword" ;
 
		try {
			// Creationof KeyStore
			KeyStore ks = KeyStore.getInstance("pkcs12");
			
			ks.load(new FileInputStream(fileKey), fileKeyPassword.toCharArray());
			String alias = (String)ks.aliases().nextElement();
			
			PrivateKey key = (PrivateKey)ks.getKey(alias, fileKeyPassword.toCharArray());
			
			Certificate[] chain = ks.getCertificateChain(alias);
 
			
			PdfReader pdfReader = new PdfReader((new File(fname)).getAbsolutePath());
			File outputFile = new File(fnameS);
			
			PdfStamper pdfStamper;
			pdfStamper = PdfStamper.createSignature(pdfReader, null, '\0', outputFile);
			PdfSignatureAppearance sap = pdfStamper.getSignatureAppearance();
			sap.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED);
			sap.setReason("Test SignPDF berthou.mc");
			sap.setLocation("");
			// Position du tampon sur la page (ici en bas a gauche page 1)
			sap.setVisibleSignature(new Rectangle(10, 10, 50, 30), 1, "sign_rbl");
 
			pdfStamper.setFormFlattening(true);
			pdfStamper.close();
 
			return true;
		}
		catch (Exception key) {
			throw new Exception(key);
		}
	}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900