دانلود سورس کد رمزنگاری با سی شارپ #C

دانلود سورس کد رمزنگاری با سی شارپ #C
در این پست، سورس کد رمزنگاری را مشاهده میکنید که با زبان برنامه نویسی سی شارپ نوشته شده است و میتوانید آنرا دانلود و استفاده نمایید.
در این برنامه جالب رمزنگای با استفاده از یک کلید انجام میشود، جهت رمز گشایی نیز از همان کلید استفاده میکند. رمزنگاری یکی از پرکاربردترین مسائلی است که در هر نمونه ای لازم خواهد شد.
شما با اجرای این برنامه فرمی را مشاهده میکنید که میتوانید هر متن یا کلمه ای را که میخواهید رمزنگاری کنید در آن وارد نمایید و با کلیک روی دکمه "Protect" متن رمزنگاری شده آن را در کادر پایینتر مشاهده کنید. همچنین میتوانید یک متن رمزگذاری شده را نیز رمزگشایی نمایید. برای این کار از دکمه "Unprotect" به همان طریق قبلی استفاده کنید. این سورس کد، با فراخوانی کلاس AES عملیات رمزنگاری و رمزگشایی را انجام میدهد.
برنامه اصلی رمزنگای با زبان سی شارپ را میتوانید از پایین صفحه دانلود کنید.
کد برنامه رمزنگاری را در زیر مشاهده میکنید. این سورس در تمامی نسخه های ویژوال استودیو قابل استفاده می باشد.
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str = "";
AES_Encryption.AES a = new AES_Encryption.AES();
str = a.Encrypt(textBox1.Text, "1", 128);
using (StreamWriter sw = new StreamWriter(@"g:1.dat"))
{
sw.Write(str);
}
richTextBox1.Text = str;
}
private void button2_Click(object sender, EventArgs e)
{
string str;
using (StreamReader sr = new StreamReader(@"g:1.dat"))
{
str = sr.ReadToEnd();
}
AES_Encryption.AES a = new AES_Encryption.AES();
richTextBox1.Text = a.Decrypt(str, "1", 128);
}
private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://WWw.SourceCodes.ir");
}
}
}
using System;
using System.Security.Cryptography;
using System.IO;
namespace AES_Encryption
{
public class AES
{
public AES()
{
}
private byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)
{
MemoryStream ms = new MemoryStream();
Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(clearData, 0, clearData.Length);
cs.Close();
byte[] encryptedData = ms.ToArray();
return encryptedData;
}
private byte[] Decrypt(byte[] cipherData, byte[] Key, byte[] IV)
{
MemoryStream ms = new MemoryStream();
Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(cipherData, 0, cipherData.Length);
cs.Close();
byte[] decryptedData = ms.ToArray();
return decryptedData;
}
public string Decrypt(string Data, string Password, int Bits)
{
byte[] cipherBytes = Convert.FromBase64String(Data);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 });
if (Bits == 128)
{
byte[] decryptedData = Decrypt(cipherBytes, pdb.GetBytes(16), pdb.GetBytes(16));
return System.Text.Encoding.Unicode.GetString(decryptedData);
}
else if (Bits == 192)
{
byte[] decryptedData = Decrypt(cipherBytes, pdb.GetBytes(24), pdb.GetBytes(16));
return System.Text.Encoding.Unicode.GetString(decryptedData);
}
else if (Bits == 256)
{
byte[] decryptedData = Decrypt(cipherBytes, pdb.GetBytes(32), pdb.GetBytes(16));
return System.Text.Encoding.Unicode.GetString(decryptedData);
}
else
{
return string.Concat(Bits);
}
}
public string Encrypt(string Data, string Password, int Bits)
{
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(Data);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 });
if (Bits == 128)
{
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(16), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
else if (Bits == 192)
{
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(24), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
else if (Bits == 256)
{
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
else
{
return string.Concat(Bits);
}
}
}
}
سورس کد رمزنگاری در #C را میتوانید بصورت رایگان دانلود کنید.
حجم فایل : 92 KB
سلام ممنون از شما ولی این برنامه چرا از طول کلید استفاده نمیکنه.یعنی اینکه خود کاربر نوع کلید رو تعیین کنه.ممنون میشم یه توضیحی راجبه کد ها بدینبا سپاس فراوان
سلامخدا خیرتون بده .پروژه کاربردی و مفیدی بود
اقا دمتون گرم .خیلی اقایید . برنامه تونم توپ بود و خیلی به درد خورد. بازم میگم دمت گرم داداش و خسته نباشید.لااااااااااااااااااااااااااااااااااایک