private static void TestDES()
        {
            var des = new DesEncryption();

            var key = des.GenerateRandomNumber(8);
            var iv  = des.GenerateRandomNumber(8);

            const string originalText = "Text to encrypt";

            var encrypted = des.Encrypt(Encoding.UTF8.GetBytes(originalText), key, iv);
            var decrypted = des.Decrypt(encrypted, key, iv);

            var decryptedMessage = Encoding.UTF8.GetString(decrypted);

            Console.WriteLine($"Original Text: {originalText}");
            Console.WriteLine($"Encrypted value: {Convert.ToBase64String(encrypted)}");
            Console.WriteLine($"Decrypted Value: {Convert.ToBase64String(decrypted)}");
            Console.WriteLine($"Decrypted Text: {decryptedMessage}");
        }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     des = new DesEncryption();
     key = DesEncryption.GenerateRandomNumber(8);
     iv  = DesEncryption.GenerateRandomNumber(8);
     if (textBox1.Text == string.Empty)
     {
         MessageBox.Show(@"Enter some text");
     }
     else
     {
         var original = textBox1.Text;
         encrypted     = des.Encrypt(Encoding.UTF8.GetBytes(original), key, iv);
         textBox2.Text = Convert.ToBase64String(encrypted);
     }
 }