Hello ,
I've to sign with an external sgnature. When i open de PDF and validate it, I
get an error message that says something like
document has been modified since sign was applied
The structure of code is:
- calc the hash
- send it to the external service
- get the external signature
- put it to de dic
Can you tell me what is wrong? or where to find the error?
thanks in advance,
Josep Maria
The code:
PdfReader reader = new PdfReader(IN_FILE);
FileStream fout = new FileStream(OUT_FILE, FileMode.Create);
PdfStamper stp = PdfStamper.CreateSignature(reader, fout, '\0');
DateTime cal = DateTime.Now;
PdfSignatureAppearance sap;
sap = stp.SignatureAppearance;
sap.SetVisibleSignature(new Rectangle(100, 100, 300, 200), 1,
"Signar");
// sap.Layer2Text = ("Prova de firma.\n\nDate: ");
//sap.Layer2Text = ("");
PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKMS,
PdfName.ADBE_PKCS7_DETACHED);
dic.Put(PdfName.TYPE, PdfName.SIG);
dic.Put(PdfName.M, new PdfDate(cal));
sap.CryptoDictionary = (dic);
// sap.Acro6Layers = (true);
int contentEstimated = 15000;
Dictionary<PdfName, int> exc = new Dictionary<PdfName, int>();
PdfName contingut = new PdfName("");
exc.Add(PdfName.CONTENTS, (contentEstimated * 2 + 2));
sap.PreClose(exc);
IDigest messageDigest = DigestUtilities.GetDigest("SHA1");
Stream data = sap.GetRangeStream();
// calc the hash
byte[] buf = new byte[8192];
int n1;
while ((n1 = data.Read(buf, 0, buf.Length)) > 0)
{
messageDigest.BlockUpdate(buf, 0, n1);
}
byte[] hash = new byte[messageDigest.GetDigestSize()];
messageDigest.DoFinal(hash, 0);
// write hash to sent it to the extenal sign util
System.IO.File.WriteAllText("C:/Reg/hash_ToBase64.txt",
Convert.ToBase64String(hash));
String shash = Convert.ToBase64String(hash);
// extenal sign util process hash
executeExe(shash);
// get PKCS#7
String spk7 = System.IO.File.ReadAllText("C:/tmp/Envelope.txt");
byte[] bpk7 = Convert.FromBase64String(spk7);
// put the PKCS#7 to disc.
PdfDictionary updates = new PdfDictionary();
byte[] out1 = new byte[contentEstimated];
System.Array.Copy(bpk7, 0, out1, 0, bpk7.Length);
updates.Put(PdfName.CONTENTS, new
PdfString(out1).SetHexWriting(true));
sap.Close(updates);
Le informamos que los datos personales de esta comunicaci?n, est?n incorporados
en un fichero bajo nuestra responsabilidad, para el tratamiento de datos de
car?cter personal, con la finalidad de mantenerle informado sobre los servicios
que ofrece Adhoc Synectic Systems, S.A.Vd., como interesado directo, tiene
derecho de acceso, rectificaci?n, cancelaci?n y oposici?n al tratamiento de la
informaci?n que le concierne y autoriza a que pase a formar parte del fichero,
ante el cual puede ejercer sus derechos, y recibir informaci?n y publicidad de
productos y servicios de Adhoc Synectic Systems, S.A.Los derechos precitados
podr?n hacerse efectivos ante Adhoc Synectic Systems, S.A., Paseo Urrutia, 97,
Local, 08042 - Barcelona, en el tel?fono 93.276.83.40 o enviando un correo
electr?nico a ad...@ad-hoc.net.(Ley Org?nica 15/1999 de 13 de Diciembre de
Protecci?n de Datos de Car?cter Personal). Este mensaje de correo electr?nico
est? dirigido exclusivamente al destinatario o destinatarios indicados en el
mismo. La informaci?n en ?l contenida puede ser confidencial y/o privada por lo
que est? totalmente prohibida su difusi?n o reproducci?n. Si usted no es el
destinatario de este mensaje, por favor devu?lvalo inmediatamente a la
direcci?n de env?o y destr?yalo.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php