public void button4_Click(object sender, EventArgs e) { // listBox1.Items.Add(" "); listBox1.Items.Clear(); listBox1.Items.Add("textul criptat cu padding:"); string selectedItem = comboBox1.Items[comboBox1.SelectedIndex].ToString(); if (selectedItem == "aes") { using (Aes myAes = Aes.Create()) { myAes.Padding = PaddingMode.ISO10126; // Encrypt the string to an array of bytes. byte[] encrypted = SymmetricAlgorithm.EncryptStringToBytes_Aes(listBox1.Items.ToString(), myAes.Key, myAes.IV); // Decrypt the bytes to a string. string roundtrip = SymmetricAlgorithm.DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV); //Display the original data and the decrypted data. // listBox1.Items.Clear(); for (int i = 0; i < 5; i++) { listBox1.Items.Add(encrypted); } } } else if (selectedItem == "cbc") { using (var random = new RNGCryptoServiceProvider()) { var key = new byte[16]; random.GetBytes(key); // Encrypt the string to an array of bytes. byte[] encrypted = AnotherCipher.EncryptStringToBytes_Aes(listBox1.Items.ToString(), key); // Decrypt the bytes to a string. string roundtrip = AnotherCipher.DecryptStringFromBytes_Aes(encrypted, key); //Display the original data and the decrypted data. listBox1.Items.Add(Convert.ToBase64String(encrypted)); } } }
private void button3_Click(object sender, EventArgs e) { listBox1.Items.Add(" "); listBox1.Items.Add("textul decriptat:"); string selectedItem = comboBox1.Items[comboBox1.SelectedIndex].ToString(); if (selectedItem == "aes") { using (Aes myAes = Aes.Create()) { myAes.Key = key1; myAes.IV = iv1; string[] roundtrip = new string[count]; for (int i = 0; i < count; i++) { // Decrypt the bytes to a string. roundtrip[i] = SymmetricAlgorithm.DecryptStringFromBytes_Aes(encrypted[i], myAes.Key, myAes.IV); } for (int i = 0; i < count; i++) { listBox1.Items.Add(roundtrip[i]); } } } else if (selectedItem == "cbc") { using (var random = new RNGCryptoServiceProvider()) { // Decrypt the bytes to a string. string[] roundtrip = new string[count]; for (int i = 0; i < count; i++) { roundtrip[i] = AnotherCipher.DecryptStringFromBytes_Aes(encrypted[i], key1); } for (int i = 0; i < count; i++) { listBox1.Items.Add(roundtrip[i]); } } } }