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 bir yolu yok ama bir wordlist kullanılıp brute force saldırısı ile bir şifreli mesajı çözme şansımız olabilir.
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 50 51 52 53 54 55 56 57 58 59 60 61 |
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; namespace md5_uygulama { public partial class Form2 : Form { //İlk önce basit bir wordlist oluşturuyoruz string[] şifreli_mesaj = { "21232f297a57a5a743894a0e4a801fc3", "827ccb0eea8a706c4c34a16891f84e7b", "d8578edf8458ce06fbc5bb76a58c5ca4", "0192023a7bbd73250516f069df18b500", "5f4dcc3b5aa765d61d8327deb882cf99" }; string[] mesajlar = { "admin", "12345", "qwerty", "admin123", "password" }; public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Burdaki amaç daha önce şifrelenmiş mesajlarla bir eşleşme yakalamaya çalışıyoruz //Eğer yakalarsak şifreli metini çözmüş oluyoruz string mesaj = textBox1.Text; for (int i=0;i<5;i++) { if(mesaj==şifreli_mesaj[i]) { textBox2.Text = mesajlar[i]; break; } } //Eğer şifre çözülmedi ise bu blok çalışıyor if(textBox2.Text=="") { MessageBox.Show("Şifre Çözülemedi"); } } } } |
Böylelikle md5 ile şifre oluşturma ve kesin olmamakla birlikte şifre kırmanın nasıl olduğunu öğrendik. Projenin kodlarını buraya tıklayarak indirebilirsiniz.