Created
June 21, 2018 16:22
-
-
Save ginxx009/116d124e899e3c248c80c1d69ab90410 to your computer and use it in GitHub Desktop.
Encryption & Decryption MD5 C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void btnDecrypt_Click(object sender, EventArgs e) | |
{ | |
byte[] data = Convert.FromBase64String(textBox4.Text); // decrypt the incrypted text | |
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) | |
{ | |
byte[] keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash)); | |
using (TripleDESCryptoServiceProvider tripDes = new TripleDESCryptoServiceProvider() { Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }) | |
{ | |
ICryptoTransform transform = tripDes.CreateDecryptor(); | |
byte[] results = transform.TransformFinalBlock(data, 0, data.Length); | |
textBox4.Text = UTF8Encoding.UTF8.GetString(results); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void btnEncrypt_Click(object sender, EventArgs e) | |
{ | |
byte[] data = UTF8Encoding.UTF8.GetBytes(textBox3.Text); | |
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) | |
{ | |
byte[] keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash)); | |
using (TripleDESCryptoServiceProvider tripDes = new TripleDESCryptoServiceProvider() { Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }) | |
{ | |
ICryptoTransform transform = tripDes.CreateEncryptor(); | |
byte[] results = transform.TransformFinalBlock(data, 0, data.Length); | |
textBox4.Text = Convert.ToBase64String(results, 0, results.Length); | |
} | |
} | |
} |
byte[] keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash));
whats the value of hash
static string hash { get; set; } = "A!9HHhi%XjjYY4YP2@Nob009X";
in file Encrypt.cs
line 2: use textBox4.Text instead of textBox3.Text
public static string Encrypt(string value)
{
var md5 = new MD5CryptoServiceProvider();
var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(value));
//converting the contents of the hash variable from byte[] to string
var result = string.Empty;
foreach (var item in hash)
{
result += item.ToString("X2"); //X2 -> HEXADECIMAL
}
return result.ToUpper();
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
byte[] keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash));
whats the value of hash