//private Certificate _certificate; internal Sig(Certificate certificate) { _dictionary = new PDFDictionary(); _dictionary.AddItem("Type", new PDFName("Sig")); _dictionary.AddItem("Filter", new PDFName("Adobe.PPKMS")); _dictionary.AddItem("SubFilter", new PDFName("adbe.pkcs7.sha1")); //_dictionary.AddItem("Filter", new PDFName("Adobe.PPKLite")); //_dictionary.AddItem("SubFilter", new PDFName("adbe.pkcs7.detached")); _dictionary.AddItem("ByteRange", new PDFArray()); //_certificate = certificate; PKCS7 pkcs = new PKCS7(certificate.Akp, certificate.Chain, null, "SHA1", true); string name = PKCS7.GetSubjectFields(pkcs.SigningCertificate).GetField("CN"); _dictionary.AddItem("Name", new PDFString(System.Text.Encoding.Default.GetBytes(name), false)); byte[] buf = pkcs.GetEncodedPKCS7(null, DateTime.Now, /*null,*/ null); byte[] digest = new byte[buf.Length /* + 64*/]; _dictionary.AddItem("Contents", new PDFString(digest, true)); }
public void WriteDigest() { PKCS7 pkcs = new PKCS7(_cert.Akp, _cert.Chain, null, "SHA1", true); for (int i = 0; i < _byteRange.Length; i += 2) { byte[] buf = new byte[_byteRange[i + 1]]; _document.Position = _byteRange[i]; _document.Read(buf, 0, _byteRange[i + 1]); pkcs.Update(buf, 0, buf.Length); } byte[] bsig = pkcs.GetEncodedPKCS7(null, DateTime.Now, null); //byte[] sbuf = new byte[bsig.Length/* +64*/]; //Array.Copy(bsig, 0, sbuf, 0, bsig.Length); // Записываем дайджест //PDFString str = new PDFString(sbuf, true); PDFString str = new PDFString(bsig, true); SaveParameters sp = new SaveParameters(_document); sp.Stream.Position = _byteRange[1]; str.Write(sp); }