public static ArraySegment <byte> ToSignatureMessageBlock(SignatureMessage message, IExchangeEncrypt publicKey) { if (message == null) { throw new ArgumentNullException("message"); } if (publicKey == null) { throw new ArgumentNullException("publicKey"); } ArraySegment <byte> value; using (Stream messageStream = message.Export(_bufferManager)) using (Stream compressStream = ContentConverter.Compress(messageStream)) using (Stream paddingStream = ContentConverter.AddPadding(compressStream, 1024 * 256)) using (Stream hashStream = ContentConverter.AddHash(paddingStream)) using (Stream cryptostream = ContentConverter.Encrypt(hashStream, publicKey)) using (Stream typeStream = ContentConverter.AddType(cryptostream, "SignatureMessage")) { value = new ArraySegment <byte>(_bufferManager.TakeBuffer((int)typeStream.Length), 0, (int)typeStream.Length); typeStream.Read(value.Array, value.Offset, value.Count); } return(value); }
public static ArraySegment <byte> ToChatMessageBlock(ChatMessage message) { if (message == null) { throw new ArgumentNullException("message"); } ArraySegment <byte> value; using (Stream messageStream = message.Export(_bufferManager)) using (Stream compressStream = ContentConverter.Compress(messageStream)) using (Stream typeStream = ContentConverter.AddType(compressStream, "ChatMessage")) { value = new ArraySegment <byte>(_bufferManager.TakeBuffer((int)typeStream.Length), 0, (int)typeStream.Length); typeStream.Read(value.Array, value.Offset, value.Count); } return(value); }