Hi all, this is my first question.
I have to sign a PDF using SHA-256 algorithm.
Somewhere I found this piece of code (this is an extraction from
my C# project classes, maybe not working now).
Where there is the comment: // <--- SUBSTITUTION (Win XP)
is my attempt to switch from SHA1 to SHA256, is this correct ?
If is wronk can you try to correct my code ?
Tnx in advance
String filePath = signableFile.getFilePath();
Org.BouncyCastle.X509.X509CertificateParser cp = new
Org.BouncyCastle.X509.X509CertificateParser();
Org.BouncyCastle.X509.X509Certificate[] chain = new
Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(card.RawData)
};
PdfReader reader = new PdfReader(filePath);
PdfStamper stp = PdfStamper.CreateSignature(reader, new
FileStream(_strategy.getOutputFileName(signableFile.getFilePath()),
FileMode.Create), '\0');
PdfSignatureAppearance sap = stp.SignatureAppearance;
sap.SetVisibleSignature(new Rectangle(100, 100, 400, 200),
reader.NumberOfPages, null);
sap.SignDate = DateTime.Now;
sap.SetCrypto(null, chain, null, null);
sap.Reason = reason;
sap.Location = location;
sap.Acro6Layers = true;
sap.Render =
PdfSignatureAppearance.SignatureRender.NameAndDescription;
PdfSignature dic = _strategy.getPdfSignature();
dic.Date = new PdfDate(sap.SignDate);
dic.Name = PdfPKCS7.GetSubjectFields(chain[0]).GetField("CN");
if (sap.Reason != null)
dic.Reason = sap.Reason;
if (sap.Location != null)
dic.Location = sap.Location;
sap.CryptoDictionary = dic;
int csize = 4000;
Hashtable exc = new Hashtable();
exc[PdfName.CONTENTS] = csize * 2 + 2;
sap.PreClose(exc);
// Effettua la firma
//HashAlgorithm sha = new SHA1CryptoServiceProvider();
HashAlgorithm sha = new SHA256Managed(); // <--- SUBSTITUTION
(Win XP)
int read = 0;
byte[] buff = new byte[8192];
while ((read = sap.RangeStream.Read(buff, 0, 8192)) > 0)
{
sha.TransformBlock(buff, 0, read, buff, 0);
}
sha.TransformFinalBlock(buff, 0, 0);
return Signer.SignMsg(sha.Hash, card, false);
// Aggiorna il dizionario
byte[] outc = new byte[csize];
PdfDictionary dic2 = new PdfDictionary();
Array.Copy(pk, 0, outc, 0, pk.Length);
dic2.Put(PdfName.CONTENTS, new
PdfString(outc).SetHexWriting(true));
sap.Close(dic2);
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
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