public List <MessageModel> getMessages(string SenderReceptor) { using (var client = new HttpClient()) { var searchedMessages = getAllUserMessages(SenderReceptor); if (searchedMessages.GetType().ToString() == "System.String") { return(null); } var decipheredMessages = new List <MessageModel>(); var decipherMessage = new SDES(); var decompressFileMessage = new CompresssDecompressActions(); var getUser = new UsersLogic(); var receptor = SenderReceptor.Split('|'); if (receptor[1] == string.Empty) { return(searchedMessages); } if (receptor[0] == LoggedUser) {//es un mensaje que yo envié var a = getUser.getUserByUsername(receptor[1]).PrivateKey; foreach (var message in searchedMessages) { var key = BigInteger.ModPow((int)message.PublicKey, a, p); var commonKey = Convert.ToString((int)key, 2); message.Message = message.Message != string.Empty ? decipherMessage.DecipherText(message.Message, commonKey) : string.Empty; decipheredMessages.Add(message); } } else {//es un mensaje recibido foreach (var message in searchedMessages) { var key = BigInteger.ModPow((int)message.PublicKey, UserPrivateKey, p); var commonKey = Convert.ToString((int)key, 2); message.Message = message.Message != string.Empty ? decipherMessage.DecipherText(message.Message, commonKey) : string.Empty; decipheredMessages.Add(message); } } return(searchedMessages); } }
public List <MessageModel> MessageThatContainsSearch(string valueToLookFor) { var loggedUser = LoggedUser; var messagesThatContains = getAllUserMessages(loggedUser); if (messagesThatContains.GetType().ToString() == "System.String") { return(null); } if (messagesThatContains != null) { var resultOfTask = new List <MessageModel>(); var decipherMessage = new SDES(); var decompressFileMessage = new CompresssDecompressActions(); var getUser = new UsersLogic(); foreach (var item in messagesThatContains) { var receptor = item.SenderReceptor.Split('|'); if (receptor[0] == LoggedUser) {//es un mensaje que yo envié var a = getUser.getUserByUsername(receptor[1]).PrivateKey; var key = BigInteger.ModPow((int)item.PublicKey, a, p); var commonKey = Convert.ToString((int)key, 2); item.Message = item.Message != string.Empty ? decipherMessage.DecipherText(item.Message, commonKey) : string.Empty; resultOfTask.Add(item); } else {//es un mensaje recibido var key = BigInteger.ModPow((int)item.PublicKey, UserPrivateKey, p); var commonKey = Convert.ToString((int)key, 2); item.Message = item.Message != string.Empty ? decipherMessage.DecipherText(item.Message, commonKey) : string.Empty; resultOfTask.Add(item); } } return(resultOfTask.FindAll(messages => messages.Message.Contains(valueToLookFor))); } else { return(null); } }