Example #1
0
        void decryptBytes(byte[] encryptedIn, String user)
        {
            AESEncryption MyAES = new AESEncryption();


            // Create a new instance of the AesManaged
            // class.  This generates a new key and initialization
            // vector (IV).
            using (AesManaged myAes = new AesManaged())
            {
                // Encrypt the string to an array of bytes.
                byte[] encrypted = encryptedIn;

                // Decrypt the bytes to a string.
                //string decrypted = MyAES.DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV);

                //Display the original data and the decrypted data.
                //Console.WriteLine("Decrypted: {0}", decrypted);

                //Console.WriteLine(System.Text.Encoding.UTF8.GetString(myAes.Key));

                List <Message> messages = MyAES.getMessages();

                //Console.WriteLine(messages[i].getAuthor() + ": " +
                //        MyAES.DecryptStringFromBytes_Aes(messages[i].getEncryptedText(),
                //        messages[i].getAESKey(), messages[i].getIVKey()));
                //Console.ReadLine();
            }
        }
Example #2
0
        void encryptString(String orig, String user)
        {
            AESEncryption MyAES = new AESEncryption();

            string original = orig;

            // Create a new instance of the AesManaged
            // class.  This generates a new key and initialization
            // vector (IV).
            using (AesManaged myAes = new AesManaged())
            {
                // Encrypt the string to an array of bytes.
                byte[] encrypted = MyAES.EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);
                Console.WriteLine(Encoding.Default.GetString(encrypted));
                Console.WriteLine();

                //Display the original data and the decrypted data.
                //Console.WriteLine("Original:   {0}", original);

                //Console.WriteLine(System.Text.Encoding.UTF8.GetString(myAes.Key));

                MyAES.sendMessage(user, encrypted, myAes.Key, myAes.IV);

                //List<Message> messages = MyAES.getMessages();
                //
                //for (int i = 0; i < messages.Count; i++)
                //{
                //    Console.WriteLine(messages[i].getAuthor() + ": " +
                //        MyAES.DecryptStringFromBytes_Aes(messages[i].getEncryptedText(), messages[i].getAESKey(), messages[i].getIVKey()));
                //}
                //Console.ReadLine();
            }
        }