TLSharp.Core.MTProto.Crypto.AesEngine.ProcessBlock C# (CSharp) Method

ProcessBlock() public method

public ProcessBlock ( byte input, int inOff, byte output, int outOff ) : int
input byte
inOff int
output byte
outOff int
return int
        public int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff)
        {
            if (WorkingKey == null)
            {
                throw new InvalidOperationException("AES engine not initialised");
            }

            if ((inOff + (32 / 2)) > input.Length)
            {
                throw new InvalidOperationException("input buffer too short");
            }

            if ((outOff + (32 / 2)) > output.Length)
            {
                throw new InvalidOperationException("output buffer too short");
            }

            UnPackBlock(input, inOff);

            if (forEncryption)
            {
                EncryptBlock(WorkingKey);
            }
            else {
                DecryptBlock(WorkingKey);
            }

            PackBlock(output, outOff);

            return BLOCK_SIZE;
        }

Usage Example

Exemplo n.º 1
0
        public static byte[] DecryptIGE(byte[] ciphertext, byte[] key, byte[] iv)
        {
            var iv1 = new byte[iv.Length / 2];
            var iv2 = new byte[iv.Length / 2];

            Array.Copy(iv, 0, iv1, 0, iv1.Length);
            Array.Copy(iv, iv1.Length, iv2, 0, iv2.Length);

            AesEngine aes = new AesEngine();

            aes.Init(false, key);

            byte[] plaintext   = new byte[ciphertext.Length];
            int    blocksCount = ciphertext.Length / 16;

            byte[] ciphertextBlock = new byte[16];
            byte[] plaintextBlock  = new byte[16];
            for (int blockIndex = 0; blockIndex < blocksCount; blockIndex++)
            {
                for (int i = 0; i < 16; i++)
                {
                    ciphertextBlock[i] = (byte)(ciphertext[blockIndex * 16 + i] ^ iv2[i]);
                }

                aes.ProcessBlock(ciphertextBlock, 0, plaintextBlock, 0);

                for (int i = 0; i < 16; i++)
                {
                    plaintextBlock[i] ^= iv1[i];
                }

                Array.Copy(ciphertext, blockIndex * 16, iv1, 0, 16);
                Array.Copy(plaintextBlock, 0, iv2, 0, 16);

                Array.Copy(plaintextBlock, 0, plaintext, blockIndex * 16, 16);
            }

            return(plaintext);
        }
All Usage Examples Of TLSharp.Core.MTProto.Crypto.AesEngine::ProcessBlock