Beispiel #1
0
        /// <summary>
        ///     Конструктор по умолчанию
        /// </summary>
        /// <param name="authKey"></param>
        /// <param name="data"></param>
        public EncryptedMessage(byte[] authKey, EncryptedData data, int x)
        {
            SHA1 sha1 = SHA1.Create();
            _authKey = authKey;
            byte[] hash = sha1.ComputeHash(authKey);
            AuthKeyId = BitConverter.ToInt64(hash, hash.Length - 8);

            hash = sha1.ComputeHash(data.SerializeNoPadding());
            var buf = new byte[16];
            Array.Copy(hash, hash.Length - 16, buf, 0, 16);
            MsgKey = new BigInteger(buf);
            _x = x;

            Data = data;
        }
        public EncryptedMessage PrepareRpcCall(SessionContainer request)
        {
            SHA1.Create();

            var encData = new EncryptedData
            {
                Salt = Salt,
                SessionId = SessionId,
                MessageId = GetNextMessageId(),
                SeqNo = GetNextSeqNo(),
                MessageData = request.Combinator.Serialize()
            };
            
            encData.MessageDataLength = encData.MessageData.Length;
            return new EncryptedMessage(_authKey, encData, 0);
        }
Beispiel #3
0
        public EncryptedMessage(byte[] authKey, byte[] plainData)
        {
            _authKey = authKey;
            using (var ms = new MemoryStream(plainData))
            {
                using (var br = new BinaryReader(ms))
                {
                    AuthKeyId = br.ReadInt64();
                    MsgKey = new BigInteger(br.ReadBytes(16));

                    // дешифруем эту дату
                    byte[] aesKey = CalculateAesKey(8, MsgKey.GetBytes());
                    byte[] aesIv = CalculateIV(8, MsgKey.GetBytes());

                    var aesIge = new Aes256IgeManaged(aesKey, aesIv);
                    Data = new EncryptedData(aesIge.Decrypt(br.ReadBytes(plainData.Length - 8 - 16)));
                }
            }
        }