Beispiel #1
0
        public async Task <IActionResult> GetConversationById([FromBody] ConversationModel model)
        {
            var receiver = await FindByEmailAsync(model.ReceiversEmail);

            var messages = new List <ReturnMessage>();

            _context.Messages.Where(m => m.ConversationId == model.ConversationID).ToList().ForEach(async me =>
            {
                var content = DecryptWithAes(me, receiver);
                if (content.Equals(String.Empty))
                {
                    var sender = await FindByEmailAsync(model.SendersEmail);
                    content    = DecryptWithAes(me, sender);
                }

                var rMessage = new ReturnMessage
                {
                    MessageId      = me.Id,
                    Content        = content,
                    ConversationId = me.ConversationId,
                    EmailOfSender  = me.EmailOfSender,
                    DataIsTrusted  = EncryptionServices.VerifyData
                                         (content,
                                         _context.PublicKeyStores.FirstOrDefault(store => store.Email == me.EmailOfSender)
                                         ?.PublicKey, me.SignedData)
                };

                messages.Add(rMessage);
            }
                                                                                                    );

            return(Ok(messages));
        }