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

Init() public method

public Init ( bool forEncryption, byte key ) : void
forEncryption bool
key byte
return void
        public void Init(bool forEncryption, byte[] key)
        {
            WorkingKey = GenerateWorkingKey(key, forEncryption);
            this.forEncryption = forEncryption;
        }

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::Init