TLSharp.Core.MTProto.Crypto.AES.DecryptWithNonces C# (CSharp) Method

DecryptWithNonces() public static method

public static DecryptWithNonces ( byte data, byte serverNonce, byte newNonce ) : byte[]
data byte
serverNonce byte
newNonce byte
return byte[]
        public static byte[] DecryptWithNonces(byte[] data, byte[] serverNonce, byte[] newNonce)
        {
            using (SHA1 hash = new SHA1Managed())
            {
                var nonces = new byte[48];

                newNonce.CopyTo(nonces, 0);
                serverNonce.CopyTo(nonces, 32);
                byte[] hash1 = hash.ComputeHash(nonces);

                serverNonce.CopyTo(nonces, 0);
                newNonce.CopyTo(nonces, 16);
                byte[] hash2 = hash.ComputeHash(nonces);

                nonces = new byte[64];
                newNonce.CopyTo(nonces, 0);
                newNonce.CopyTo(nonces, 32);
                byte[] hash3 = hash.ComputeHash(nonces);

                using (var keyBuffer = new MemoryStream(32))
                using (var ivBuffer = new MemoryStream(32))
                {
                    keyBuffer.Write(hash1, 0, hash1.Length);
                    keyBuffer.Write(hash2, 0, 12);

                    ivBuffer.Write(hash2, 12, 8);
                    ivBuffer.Write(hash3, 0, hash3.Length);
                    ivBuffer.Write(newNonce, 0, 4);

                    return DecryptIGE(data, keyBuffer.ToArray(), ivBuffer.ToArray());
                }
            }
        }