public void WriteBodyToSignThenEncrypt(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm) { XmlBuffer buffer = new XmlBuffer(int.MaxValue); XmlDictionaryWriter fragmentingWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max); WriteBodyToSignThenEncryptWithFragments(canonicalStream, false, null, encryptedData, algorithm, fragmentingWriter); ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(this.startBodyFragment.GetBuffer(), 0, (int)this.startBodyFragment.Length); ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(this.endBodyFragment.GetBuffer(), 0, (int)this.endBodyFragment.Length); buffer.CloseSection(); buffer.Close(); this.startBodyFragment = null; this.endBodyFragment = null; XmlDictionaryReader reader = buffer.GetReader(0); reader.MoveToContent(); this.bodyPrefix = reader.Prefix; if (reader.HasAttributes) { this.bodyAttributes = XmlAttributeHolder.ReadAttributes(reader); } reader.Close(); }