Esempio n. 1
0
        public int ReadAndDecrypt(byte[] buffer, int offset, int count)
        {
            int queueSize  = data.Count;
            int sizeToRead = count - queueSize;

            if (sizeToRead > 0)
            {
                int alignedSize = sizeToRead + ((~sizeToRead + 1) & 0xf);
                for (int i = 0; i < alignedSize / 16; i++)
                {
                    //long ax = System.currentTimeMillis();
                    byte[] cipherText = new byte[RarRijndael.CRYPTO_BLOCK_SIZE];
                    actualStream.Read(cipherText, 0, RarRijndael.CRYPTO_BLOCK_SIZE);

                    var readBytes = rijndael.ProcessBlock(cipherText);
                    foreach (var readByte in readBytes)
                    {
                        data.Enqueue(readByte);
                    }
                }

                for (int i = 0; i < count; i++)
                {
                    buffer[offset + i] = data.Dequeue();
                }
            }
            return(count);
        }
Esempio n. 2
0
        private byte[] ReadAndDecryptBytes(int count)
        {
            int queueSize  = data.Count;
            int sizeToRead = count - queueSize;

            if (sizeToRead > 0)
            {
                int alignedSize = sizeToRead + ((~sizeToRead + 1) & 0xf);
                for (int i = 0; i < alignedSize / 16; i++)
                {
                    //long ax = System.currentTimeMillis();
                    byte[] cipherText = base.ReadBytes(16);
                    var    readBytes  = rijndael.ProcessBlock(cipherText);
                    foreach (var readByte in readBytes)
                    {
                        data.Enqueue(readByte);
                    }
                }
            }

            var decryptedBytes = new byte[count];

            for (int i = 0; i < count; i++)
            {
                decryptedBytes[i] = data.Dequeue();
            }
            return(decryptedBytes);
        }