/** * Return the uncompressed content, throwing an exception if the data size * is greater than the passed in limit. If the content is exceeded getCause() * on the CMSException will contain a StreamOverflowException * * @param limit maximum number of bytes to read * @return the content read * @throws CMSException if there is an exception uncompressing the data. */ public byte[] GetContent(int limit) { CompressedData comData = CompressedData.GetInstance(contentInfo.Content); ContentInfo content = comData.EncapContentInfo; Asn1OctetString bytes = (Asn1OctetString)content.Content; ZInputStream zIn = new ZInputStream(new MemoryStream(bytes.GetOctets(), false)); try { return CmsUtilities.StreamToByteArray(zIn, limit); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } }
/** * Return the uncompressed content. * * @return the uncompressed content * @throws CmsException if there is an exception uncompressing the data. */ public byte[] GetContent() { CompressedData comData = CompressedData.GetInstance(contentInfo.Content); ContentInfo content = comData.EncapContentInfo; Asn1OctetString bytes = (Asn1OctetString) content.Content; ZInputStream zIn = new ZInputStream(bytes.GetOctetStream()); try { return CmsUtilities.StreamToByteArray(zIn); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } finally { zIn.Close(); } }
private void DecryptEncryptedDataStream(Stream outputPlaintextStream, ICryptoTransform decryptor, AxCryptDataStream encryptedDataStream, ProgressContext progress) { Exception savedExceptionIfCloseCausesCryptographicException = null; try { if (DocumentHeaders.IsCompressed) { using (CryptoStream deflatedPlaintextStream = new CryptoStream(encryptedDataStream, decryptor, CryptoStreamMode.Read)) { using (ZInputStream inflatedPlaintextStream = new ZInputStream(deflatedPlaintextStream)) { try { CopyToWithCount(inflatedPlaintextStream, outputPlaintextStream, encryptedDataStream, progress); } catch (Exception ex) { savedExceptionIfCloseCausesCryptographicException = ex; throw; } } } } else { using (Stream plainStream = new CryptoStream(encryptedDataStream, decryptor, CryptoStreamMode.Read)) { try { CopyToWithCount(plainStream, outputPlaintextStream, encryptedDataStream, progress); } catch (Exception ex) { savedExceptionIfCloseCausesCryptographicException = ex; throw; } } } } catch (CryptographicException) { throw savedExceptionIfCloseCausesCryptographicException; } }