Documento sem títuloHi all,
The acrobat reader return this Error "Document has been altered or corrupted"
but the signer's identity is valid ...
Any suggestions ??? Tks ...
this is my code ...
privateKey = (PrivateKey) keyStore.getKey(alias, new
String("123456").toCharArray());
chain = keyStore.getCertificateChain(alias);
private static void signDocument() throws GeneralSecurityException,
IOException, DocumentException {
PdfReader reader = new
PdfReader("E:\\AcessoFree\\DnaCam\\original.pdf");
FileOutputStream fout = new
FileOutputStream("E:\\AcessoFree\\DnaCam\\signed.pdf");
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setReason("Emissão de Certidão Digital");
sap.setLocation("Brasil");
java.util.Calendar now = java.util.Calendar.getInstance();
sap.setSignDate(now);
sap.setCrypto(null, chain, null, PdfSignatureAppearance.SELF_SIGNED);
// comment next line to have an invisible signature
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
sap.setExternalDigest(new byte[128], null, "RSA");
sap.preClose();
byte[] content = streamToByteArray(sap.getRangeStream());
Signature sign = Signature.getInstance("SHA1withRSA", p);
sign.initSign(privateKey);
byte[] signatureBytes = sign.sign();
sign.update(content);
PdfPKCS7 sig = sap.getSigStandard().getSigner();
sig.setExternalDigest(signatureBytes, null, "RSA");
//byte[] hash = MessageDigest.getInstance("SHA-1").digest(content);
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.CONTENTS, new
PdfString(sig.getEncodedPKCS1()).setHexWriting(true));
sap.close(dic);
}
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar