Exemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         string dec = ManagedAesSample.DecryptFromString(txtEnc.Text, txtKey.Text);
         txtDec.Text = dec;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.ToString());
     }
 }
Exemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         string enc = ManagedAesSample.EncryptToString(txtToEnc.Text, txtKey.Text);
         txtEnc.Text = enc;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.ToString());
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Starting with a console application
            string originalText = "";
            string key          = "";

            Console.WriteLine("Choose Encrypt/Decrypt - 1/2");
            int mode = int.Parse(Console.ReadLine());

            if (mode == 1)
            {
                Console.WriteLine("Enter text to encrypt");
                originalText = Console.ReadLine();
                Console.WriteLine("Enter the secret key");
                key = Console.ReadLine();



                byte[] plainText      = new byte[16];
                byte[] keybytes       = new byte[16];
                byte[] cipherText     = new byte[16];
                byte[] decryptedBytes = new byte[16];



                plainText = Encoding.UTF8.GetBytes(originalText);
                keybytes  = Encoding.UTF8.GetBytes(key);

                AesLib.Aes a = new AesLib.Aes(AesLib.Aes.KeySize.Bits192, keybytes);

                byte[] enciphered = a.AESEncryptPadding(originalText);


                a.Dump();

                Console.WriteLine("With AES LIB " + a.VisualizeInMonkey(enciphered));
                Console.WriteLine("With AES LIB " + a.VisualizeInHex(enciphered));


                byte[] verified = ManagedAesSample.EncryptAesManaged(originalText, keybytes);

                Console.WriteLine("With AES INTERNAL " + a.VisualizeInMonkey(verified));
                Console.WriteLine("With AES INTERNAL " + a.VisualizeInHex(verified));

                Console.ReadKey();

                AesLib.Aes b = new AesLib.Aes(AesLib.Aes.KeySize.Bits192, keybytes);

                byte[] deciphered = b.Decrypt(enciphered);

                Console.WriteLine("Decyphered: " + Encoding.UTF8.GetString(deciphered));


                //a.Decrypt(cipherText, decryptedBytes);
                //a.Dump();

                //string decryption_hex = string.Join(" ", plainText.Select(x => x.ToString("X2")));
                //string decryption_clear = string.Join(" ", decryptedBytes.Select(x => x.ToString("X2")));

                //Console.WriteLine($"Decrypted in hex: {decryption_hex}");
                //Console.WriteLine($"Decrypted in plain text: {Encoding.UTF8.GetString(decryptedBytes)}");
            }
            else
            {
                Console.WriteLine("Not implemented yet");
            }
        }