Base64 Encoding represent binary data in as ASCII string format. I have created a small desktop application that will encrypt and Decrypt string.
Code base associated with the application:
private void button1_Click(object sender, EventArgs e)
{
String Result = EncryptBase64(txtEncodeString.Text.Trim().ToString());
txtEncodeValue.Text = Result;
}
public static string EncryptBase64(string value)
{
string result = "";
try
{
if (!string.IsNullOrEmpty(value))
{
byte[] bytes = System.Text.UnicodeEncoding.UTF8.GetBytes(value);
result = Convert.ToBase64String(bytes);
}
}
catch { }
return result;
}
private void btnDecode_Click(object sender, EventArgs e)
{
String Result = DecryptBase64(txtDecodeString.Text.Trim().ToString());
txtDecodeValue.Text = Result;
}
public static string DecryptBase64(string value)
{
string result = "";
try
{
byte[] bytes = Convert.FromBase64String(value);
result = System.Text.Encoding.UTF8.GetString(bytes);
}
catch { }
return result;
}
No comments:
Post a Comment