public static byte[] Digest(Org.BouncyCastle.Crypto.IDigest d, byte[] b, int offset, int len) { d.BlockUpdate(b, offset, len); byte[] r = new byte[d.GetDigestSize()]; d.DoFinal(r, 0); return(r); }
} // End Function GetBouncyAlgorithm protected override byte[] HashData(byte[] data, int offset, int count, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { Org.BouncyCastle.Crypto.IDigest digest = GetBouncyAlgorithm(hashAlgorithm); byte[] retValue = new byte[digest.GetDigestSize()]; digest.BlockUpdate(data, offset, count); digest.DoFinal(retValue, 0); return(retValue); } // End Function HashData
public static byte[] Digest(System.IO.Stream data, Org.BouncyCastle.Crypto.IDigest messageDigest) { byte[] buf = new byte[8192]; int n; while ((n = data.Read(buf, 0, buf.Length)) > 0) { messageDigest.BlockUpdate(buf, 0, n); } byte[] r = new byte[messageDigest.GetDigestSize()]; messageDigest.DoFinal(r, 0); return(r); }
} // End Function HashData protected override byte[] HashData(System.IO.Stream data, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { Org.BouncyCastle.Crypto.IDigest digest = GetBouncyAlgorithm(hashAlgorithm); byte[] buffer = new byte[4096]; int cbSize; while ((cbSize = data.Read(buffer, 0, buffer.Length)) > 0) { digest.BlockUpdate(buffer, 0, cbSize); } byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); return(hash); } // End Function HashData
private static byte[] GetByteRangeDigest(PdfDocument document, PdfPKCS7 pkcs7, PdfSignature signature, string digestAlg) { Org.BouncyCastle.Crypto.IDigest digest = Org.BouncyCastle.Security.DigestUtilities.GetDigest(digestAlg); iText.Kernel.Pdf.PdfArray b = signature.GetByteRange(); iText.IO.Source.RandomAccessFileOrArray rf = document.GetReader().GetSafeFile(); Stream rg = null; try { rg = new iText.IO.Source.RASInputStream(new iText.IO.Source.RandomAccessSourceFactory().CreateRanged(rf.CreateSourceView(), b.ToLongArray( ))); byte[] buf = new byte[8192]; int rd; while ((rd = rg.Read(buf, 0, buf.Length)) > 0) { digest.BlockUpdate(buf, 0, rd); } byte[] dig = new byte[digest.GetDigestSize()]; digest.DoFinal(dig, 0); return(dig); } catch (Exception e) { throw new iText.Kernel.PdfException(e); } finally { try { if (rg != null) { rg.Dispose(); } } catch (System.IO.IOException e) { // this really shouldn't ever happen - the source view we use is based on a Safe view, which is a no-op anyway throw new iText.Kernel.PdfException(e); } } }
public void BlockUpdate(byte[] input, int inOff, int length) { _digest.BlockUpdate(input, inOff, length); }
/// <inheritdoc/> protected override void HashCore(byte[] array, int ibStart, int cbSize) { digest.BlockUpdate(array, ibStart, cbSize); }