Exemplo n.º 1
0
        public static void SDESProcess(string user1, string user2)
        {
            int exit = 1;

            while (exit == 1)
            {
                Console.Clear();
                Console.WriteLine(" --- PRUEBAS ---");
                Console.WriteLine("\n --- MongoDB ---");
                var client     = new MongoClient("mongodb://localhost:27017");
                var db         = client.GetDatabase("local");
                var messagesDB = db.GetCollection <MessageModel>("messages");
                List <MessageModel> result1 = messagesDB.Find(x => (x.Transmitter == user1 && x.Receiver == user2 && x.Type == 1) || (x.Transmitter == user2 && x.Receiver == user1 && x.Type == 1)).ToList().OrderBy(x => x.Date).ToList();
                for (int i = 0; i < result1.Count; i++)
                {
                    Console.WriteLine((i + 1) + ") " + result1[i].Transmitter + " | " + result1[i].Receiver + " | " + result1[i].Id + " | " + result1[i].Date);
                }
                Console.WriteLine("\nIngrese el número del mensaje a descrifrar");
                int option = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("\nIngrese la llave");
                int key = Convert.ToInt32(Console.ReadLine());

                SDES sdes = new SDES();
                sdes.SetKeys(key);

                Console.WriteLine($"\nMensaje cifrado\n{result1[option - 1].Content}\n\nMensaje descifrado\n{ConvertToString(sdes.DecryptText(ConvertToByte(result1[option - 1].Content)))}");

                Console.WriteLine("\n¿Desea descifrar otro mensaje? (1) Sí (0) No");
                exit = Convert.ToInt32(Console.ReadLine());
            }
        }
Exemplo n.º 2
0
        private string EncryptPassword(string password)
        {
            SDES sdes = new SDES();

            sdes.SetKeys(10);

            byte[] password_encrypted = sdes.EncryptText(ConvertToByte(password));
            return(ConvertToString(password_encrypted));
        }
Exemplo n.º 3
0
        public MessageModel EncryptMessage(MessageModel message)
        {
            var usersDB         = db.GetCollection <UserModel>("users");
            int trasnmitter_key = usersDB.Find(x => x.UserName == message.Transmitter).ToList()[0].Key;
            int receiver_key    = usersDB.Find(x => x.UserName == message.Receiver).ToList()[0].Key;

            DiffieHellman df        = new DiffieHellman();
            int           publickey = df.GetPublicKey(trasnmitter_key);
            int           commonkey = df.GetCommonKey(publickey, receiver_key);

            SDES sdes = new SDES();

            sdes.SetKeys(commonkey);
            message.Content = ConvertToString(sdes.EncryptText(ConvertToByte(message.Content)));

            return(message);
        }