C# ile MD5 Encrypt ve Decrypt
MD5 basitçe anlatırsak istenilen boyuttaki bir mesajı 128 bit uzunluğa sahip bir sonuç üretir. C# programlama dili ile ilk önce bir mesajı nasıl Encrpt(Şifreleme) hale getirebiliriz ona bakalım daha sonra nasıl Decrypt(Şifre Çözme) edebileceğimize bakacağız. Görsel Kısım: Kod Kısmı:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; //Şifreleme için kütüphaneleri ekleyelim using System.Security.Cryptography; namespace md5_uygulama { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //MD5 şifrelemesini yapacak sınıfı ekliyoruz public static string MD5Hash(string text) { MD5 md5 = new MD5CryptoServiceProvider(); //metnin boyutuna göre hash hesaplar md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text)); //hesapladıktan sonra hashi alır byte[] result = md5.Hash; StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < result.Length; i++) { //her baytı 2 hexadecimal hane olarak değiştirir strBuilder.Append(result[i].ToString("x2")); } return strBuilder.ToString(); } private void button1_Click(object sender, EventArgs e) { textBox2.Text = MD5Hash(textBox1.Text); } } } |
Herhangi bir mesajı nasıl şifreleyebileceğimizi anlattık. Şimdi şifrelenmiş bir mesajı nasıl çözebileceğimize bakarsak bunun kesin…
Devamı
SON YORUMLAR