Hello, I'm trying to run my program done in C # with Windows Application, but it's giving a compilation error that I can not solve. Thanks to whoever can help me! Thankful ! (The error is happening in void Decode method)
using System;
using System.Linq;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace CriptografiaTrabalho
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
textBox2.Text = Codificar(textBox1.Text);
}
void Button2Click(object sender, EventArgs e)
{
textBox3.Text = Decodificar(textBox2.Text);
}
public static string Codificar(string entrada)
{
TripleDESCryptoServiceProvider cript = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
try
{
if (entrada.Trim() !="")
{
string chave = "cx3f2e4ct4d2";
cript.Key = md5.ComputeHash(Encoding.Default.GetBytes(chave));
cript.Mode = CipherMode.ECB;
ICryptoTransform dencrypt = cript.CreateEncryptor();
byte[] buff = Encoding.Default.GetBytes(entrada);
return Convert.ToBase64String(dencrypt.TransformFinalBlock(buff, 0, buff.Length));
}
else
{
return "";
}
}
catch (Exception exception)
{
throw exception;
}
finally
{
cript = null;
md5 = null;
}
}
public static string Decodificar(string entrada)
{
TripleDESCryptoServiceProvider decript = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
try
{
if (entrada.Trim() != "")
{
string chave = "cx3f2e4ct4d2";
decript.Key = md5.ComputeHash(Encoding.Default.GetBytes(chave));
decript.Mode = CipherMode.ECB;
ICryptoTransform dencrypt = decript.CreateEncryptor();
byte[] buff = Convert.FromBase64String(entrada);
return Encoding.Default.GetString(dencrypt.TransformFinalBlock(buff, 0, buff.Length));
}
}
catch (Exception exception)
{
throw exception;
}
finally
{
decript = null;
md5 = null;
}
}
}
}