31-12-21, 11:34 PM
``` namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string method_1(string string_0)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (byte b in Encoding.UTF8.GetBytes(string_0))
{
stringBuilder.Append(string.Format("{0:x2}", b));
}
return stringBuilder.ToString();
}
public static string Encrypt(string plainText)
{
string encrypt_key = ("123456789");
byte[] key = SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(encrypt_key));
byte[] iv = new byte[16];
Aes aes = Aes.Create();
aes.Mode = CipherMode.CBC;
aes.Key = key;
aes.IV = iv;
MemoryStream memoryStream = new MemoryStream();
ICryptoTransform transform = aes.CreateEncryptor();
CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);
byte[] bytes = Encoding.ASCII.GetBytes(plainText);
cryptoStream.Write(bytes, 0, bytes.Length);
cryptoStream.FlushFinalBlock();
byte[] array = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
return Convert.ToBase64String(array, 0, array.Length);
}
public static string Decrypt(string cipherText)
{
{
string decrypt_key = ("123456789");
byte[] key = SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(decrypt_key));
byte[] iv = new byte[16];
Aes aes = Aes.Create();
aes.Mode = CipherMode.CBC;
aes.Key = key;
aes.IV = iv;
MemoryStream memoryStream = new MemoryStream();
ICryptoTransform transform = aes.CreateEncryptor();
CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);
byte[] bytes = Convert.FromBase64String(cipherText);
cryptoStream.Write(bytes, 0, bytes.Length);
cryptoStream.FlushFinalBlock();
byte[] array = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
return Encoding.ASCII.GetString(array, 0, array.Length);
}
}
private void Button1_Click(object sender, EventArgs e)
{
textBoxen.Text = Encrypt(textBoxva.Text);
}
private void Button2_Click(object sender, EventArgs e)
{
textBoxde.Text = Decrypt(textBoxen.Text);
}
```
بس النتيجة ما تظهر
ممكن افادة