Incog.Messaging.IncogStream.ReadBytes C# (CSharp) Method

ReadBytes() public method

Read a byte array from the underlying stream.
public ReadBytes ( ) : byte[]
return byte[]
        public byte[] ReadBytes()
        {
            // Fetch the unencrypted length from the beginning of the stream
            ushort length = this.ReadUInt16();
            if (length == 0) return null;

            // Create a buffer the size of the length and populate the buffer
            byte[] buffer = new byte[length];
            this.innerStream.Read(buffer, 0, length);

            // Decrypt the buffer and return the results
            try
            {
                byte[] cleartext = this.mycrypt.GetBytes(buffer, Cryptkeeper.Action.Decrypt);
                return cleartext;
            }
            catch (System.Security.Cryptography.CryptographicException)
            {
                // The decryption process failed
                return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }