Quote:
Originally Posted by ©Hyperlink
i do it so i can use the icon.
Is it so hard to use the shortcut?
|
Just to make you angry.. and teach you a lesson..
CryptorEngine.cs
Code:
public class CryptorEngine
{
// Methods
public static string Decrypt(string cipherString, bool useHashing)
{
byte[] buffer;
byte[] inputBuffer = Convert.FromBase64String(cipherString);
AppSettingsReader reader = new AppSettingsReader();
string s = (string) reader.GetValue("SecurityKey", typeof(string));
if (useHashing)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
buffer = provider.ComputeHash(Encoding.UTF8.GetBytes(s));
provider.Clear();
}
else
{
buffer = Encoding.UTF8.GetBytes(s);
}
TripleDESCryptoServiceProvider provider2 = new TripleDESCryptoServiceProvider();
provider2.Key = buffer;
provider2.Mode = CipherMode.ECB;
provider2.Padding = PaddingMode.PKCS7;
byte[] bytes = provider2.CreateDecryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);
provider2.Clear();
return Encoding.UTF8.GetString(bytes);
}
public static string Encrypt(string toEncrypt, bool useHashing)
{
byte[] buffer;
byte[] bytes = Encoding.UTF8.GetBytes(toEncrypt);
AppSettingsReader reader = new AppSettingsReader();
string s = (string) reader.GetValue("SecurityKey", typeof(string));
if (useHashing)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
buffer = provider.ComputeHash(Encoding.UTF8.GetBytes(s));
provider.Clear();
}
else
{
buffer = Encoding.UTF8.GetBytes(s);
}
TripleDESCryptoServiceProvider provider2 = new TripleDESCryptoServiceProvider();
provider2.Key = buffer;
provider2.Mode = CipherMode.ECB;
provider2.Padding = PaddingMode.PKCS7;
byte[] inArray = provider2.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
provider2.Clear();
return Convert.ToBase64String(inArray, 0, inArray.Length);
}
}
frmMain.cs
Code:
public class frmMain : Form
{
// Fields
private FileSystemWatcher _fileMonitor;
private string _fileName;
private bool _wasChanged;
private bool _wasCreated;
private bool _wasRenamed;
private Button btnDecrypt;
private Button btnEncrypt;
private Button btnLoadFile;
private Button btnSaveFile;
private Button button1;
private Button button2;
private IContainer components;
private Label dwdw;
private ErrorProvider error;
private Label label1;
private Label label2;
private Label label3;
private PictureBox pictureBox1;
private TextBox txtCipherText;
private TextBox txtClearText;
private TextBox txtDecryptedText;
private TextBox txtFileContent;
// Methods
public frmMain()
{
this.InitObjects();
this.InitializeComponent();
}
private void btnDecrypt_Click(object sender, EventArgs e)
{
if (this.txtClearText.Text == "")
{
this.error.SetError(this.txtClearText, "Enter the text you want to encrypt");
}
else
{
this.error.Clear();
string toEncrypt = this.txtClearText.Text.Trim();
CryptorEngine.Encrypt(toEncrypt, true);
string str2 = CryptorEngine.Decrypt(toEncrypt, true);
this.txtCipherText.Visible = false;
this.txtDecryptedText.Text = str2;
this.txtDecryptedText.Visible = true;
this.label3.Visible = true;
MessageBox.Show("You have successfull decrypted the encrypted data.");
}
}
private void btnEncrypt_Click(object sender, EventArgs e)
{
if (this.txtClearText.Text == "")
{
this.error.SetError(this.txtClearText, "Enter the text you want to encrypt");
}
else
{
this.error.Clear();
string str2 = CryptorEngine.Encrypt(this.txtClearText.Text.Trim(), true);
this.txtDecryptedText.Visible = false;
this.label3.Visible = true;
this.txtCipherText.Text = str2;
this.btnDecrypt.Enabled = true;
this.txtCipherText.Visible = true;
MessageBox.Show("You have successfull encrypted the data.");
}
}
private void btnLoadFile_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.CheckFileExists = true;
dialog.Multiselect = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
this._fileName = dialog.FileName;
if (this._fileName != string.Empty)
{
this.LoadFileContent();
}
}
}
private void btnLoadFile_Click_1(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.CheckFileExists = true;
dialog.Multiselect = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
this._fileName = dialog.FileName;
if (this._fileName != string.Empty)
{
this.LoadFileContent();
}
}
}
private void btnSaveFile_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text Files (*.txt)|*.txt|ini files (*.ini)|*.cs|DAT files (*.dat)|*.dat|All files (*.*)|*.*";
dialog.SupportMultiDottedExtensions = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
this._fileName = dialog.FileName;
if (!string.IsNullOrEmpty(this._fileName))
{
this.SaveFileContent();
}
}
}
private void btnSaveFile_Click_1(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text Files (*.txt)|*.txt|ini files (*.ini)|*.cs|DAT files (*.dat)|*.dat|All files (*.*)|*.*";
dialog.SupportMultiDottedExtensions = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
this._fileName = dialog.FileName;
if (!string.IsNullOrEmpty(this._fileName))
{
this.SaveFileContent();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
this.txtCipherText.Visible = true;
this.txtDecryptedText.Visible = true;
MessageBox.Show("You have successfull showed both texts.");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("You will now restart Sdl Creator.");
Application.Restart();
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void FileMonitor_OnChanged(object sender, FileSystemEventArgs e)
{
if ((!this._wasCreated && (e.ChangeType == WatcherChangeTypes.Created)) || (!this._wasChanged && (e.ChangeType == WatcherChangeTypes.Changed)))
{
DialogResult result = MessageBox.Show("The content of the file " + e.Name + " was changed or had errorload. \r\nDo you want to reload it ?", "File was changed successfull", MessageBoxButtons.OKCancel);
if (e.ChangeType == WatcherChangeTypes.Changed)
{
this._wasChanged = true;
}
else
{
this._wasCreated = true;
}
if (result == DialogResult.OK)
{
base.BeginInvoke(new LoadContentCallback(this.LoadFileContent));
}
}
else if ((e.ChangeType == WatcherChangeTypes.Changed) && this._wasChanged)
{
this._wasChanged = false;
}
else if ((e.ChangeType == WatcherChangeTypes.Created) && this._wasCreated)
{
this._wasCreated = false;
}
}
private void FileMonitor_OnDeleted(object sender, FileSystemEventArgs e)
{
if (MessageBox.Show("The file " + e.Name + " was deleted. \r\nDo you want to remove it from Sdl Creator?", "File was deleted successfull", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this._fileMonitor.Dispose();
base.BeginInvoke(new LoadContentCallback(this.ResetUiContent));
}
}
private void FileMonitor_OnRenamed(object sender, RenamedEventArgs e)
{
if (!this._wasRenamed)
{
DialogResult result = MessageBox.Show("The file " + e.OldName + " has been renamed. \r\nDo you want to load the renamed file?", "File was renamed successfull.", MessageBoxButtons.OKCancel);
this._wasRenamed = true;
if (result == DialogResult.OK)
{
this._fileName = e.FullPath;
base.BeginInvoke(new LoadContentCallback(this.LoadFileContent));
}
}
else
{
this._wasRenamed = false;
}
}
private void InitializeComponent()
{
this.components = new Container();
ComponentResourceManager manager = new ComponentResourceManager(typeof(frmMain));
this.btnEncrypt = new Button();
this.btnDecrypt = new Button();
this.txtClearText = new TextBox();
this.txtCipherText = new TextBox();
this.label1 = new Label();
this.label2 = new Label();
this.label3 = new Label();
this.txtDecryptedText = new TextBox();
this.error = new ErrorProvider(this.components);
this.btnSaveFile = new Button();
this.txtFileContent = new TextBox();
this.dwdw = new Label();
this.btnLoadFile = new Button();
this.pictureBox1 = new PictureBox();
this.button1 = new Button();
this.button2 = new Button();
((ISupportInitialize) this.error).BeginInit();
((ISupportInitialize) this.pictureBox1).BeginInit();
base.SuspendLayout();
this.btnEncrypt.Location = new Point(5, 0x191);
this.btnEncrypt.Name = "btnEncrypt";
this.btnEncrypt.Size = new Size(0xd0, 0x17);
this.btnEncrypt.TabIndex = 0;
this.btnEncrypt.Text = "Encrypt";
this.btnEncrypt.UseVisualStyleBackColor = true;
this.btnEncrypt.Click += new EventHandler(this.btnEncrypt_Click);
this.btnDecrypt.Location = new Point(0xdb, 0x191);
this.btnDecrypt.Name = "btnDecrypt";
this.btnDecrypt.Size = new Size(0xd0, 0x17);
this.btnDecrypt.TabIndex = 1;
this.btnDecrypt.Text = "Decrypt";
this.btnDecrypt.UseVisualStyleBackColor = true;
this.btnDecrypt.Click += new EventHandler(this.btnDecrypt_Click);
this.txtClearText.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
this.txtClearText.Location = new Point(7, 0x19);
this.txtClearText.Multiline = true;
this.txtClearText.Name = "txtClearText";
this.txtClearText.ScrollBars = ScrollBars.Both;
this.txtClearText.Size = new Size(0x350, 0x6a);
this.txtClearText.TabIndex = 2;
this.txtClearText.Text = "TEXT TO ENCRYPT/DECRYPT";
this.txtClearText.TextChanged += new EventHandler(this.txtClearText_TextChanged);
this.txtCipherText.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
this.txtCipherText.Location = new Point(8, 150);
this.txtCipherText.Multiline = true;
this.txtCipherText.Name = "txtCipherText";
this.txtCipherText.ReadOnly = true;
this.txtCipherText.ScrollBars = ScrollBars.Both;
this.txtCipherText.Size = new Size(0x185, 0x6a);
this.txtCipherText.TabIndex = 3;
this.txtCipherText.TabStop = false;
this.txtCipherText.TextChanged += new EventHandler(this.txtCipherText_TextChanged);
this.label1.AutoSize = true;
this.label1.Location = new Point(4, 9);
this.label1.Name = "label1";
this.label1.Size = new Size(0x1c, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Text";
this.label2.AutoSize = true;
this.label2.Location = new Point(0x1c6, 0x86);
this.label2.Name = "label2";
this.label2.Size = new Size(0x4d, 13);
this.label2.TabIndex = 5;
this.label2.Text = "DecryptedText";
this.label3.AutoSize = true;
this.label3.Location = new Point(5, 0x86);
this.label3.Name = "label3";
this.label3.Size = new Size(0x4f, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Encrypted Text";
this.txtDecryptedText.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
this.txtDecryptedText.Location = new Point(0x1ce, 150);
this.txtDecryptedText.Multiline = true;
this.txtDecryptedText.Name = "txtDecryptedText";
this.txtDecryptedText.ReadOnly = true;
this.txtDecryptedText.ScrollBars = ScrollBars.Both;
this.txtDecryptedText.Size = new Size(0x189, 0x6a);
this.txtDecryptedText.TabIndex = 7;
this.txtDecryptedText.TabStop = false;
this.error.ContainerControl = this;
this.btnSaveFile.Location = new Point(0x1b1, 0x191);
this.btnSaveFile.Name = "btnSaveFile";
this.btnSaveFile.Size = new Size(0xd0, 0x17);
this.btnSaveFile.TabIndex = 8;
this.btnSaveFile.Text = "Save";
this.btnSaveFile.UseVisualStyleBackColor = true;
this.btnSaveFile.Click += new EventHandler(this.btnSaveFile_Click_1);
this.txtFileContent.Location = new Point(5, 0x113);
this.txtFileContent.Multiline = true;
this.txtFileContent.Name = "txtFileContent";
this.txtFileContent.ScrollBars = ScrollBars.Both;
this.txtFileContent.Size = new Size(850, 120);
this.txtFileContent.TabIndex = 9;
this.dwdw.AutoSize = true;
this.dwdw.Location = new Point(5, 0x103);
this.dwdw.Name = "dwdw";
this.dwdw.Size = new Size(0x42, 13);
this.dwdw.TabIndex = 10;
this.dwdw.Text = "Text to save";
this.btnLoadFile.Location = new Point(0x287, 0x191);
this.btnLoadFile.Name = "btnLoadFile";
this.btnLoadFile.Size = new Size(0xd0, 0x17);
this.btnLoadFile.TabIndex = 11;
this.btnLoadFile.Text = "Load";
this.btnLoadFile.UseVisualStyleBackColor = true;
this.btnLoadFile.Click += new EventHandler(this.btnLoadFile_Click_1);
this.pictureBox1.Image = (Image) manager.GetObject("pictureBox1.Image");
this.pictureBox1.Location = new Point(0, 460);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new Size(850, 50);
this.pictureBox1.TabIndex = 12;
this.pictureBox1.TabStop = false;
this.button1.Location = new Point(5, 0x1af);
this.button1.Name = "button1";
this.button1.Size = new Size(0x1a6, 0x17);
this.button1.TabIndex = 13;
this.button1.Text = "Show both texts";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new EventHandler(this.button1_Click);
this.button2.Location = new Point(0x1b1, 0x1af);
this.button2.Name = "button2";
this.button2.Size = new Size(0x1a6, 0x17);
this.button2.TabIndex = 14;
this.button2.Text = "New Crypto";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new EventHandler(this.button2_Click);
base.AutoScaleDimensions = new SizeF(6f, 13f);
base.AutoScaleMode = AutoScaleMode.Font;
base.ClientSize = new Size(0x35e, 0x201);
base.Controls.Add(this.button2);
base.Controls.Add(this.button1);
base.Controls.Add(this.pictureBox1);
base.Controls.Add(this.btnLoadFile);
base.Controls.Add(this.dwdw);
base.Controls.Add(this.txtFileContent);
base.Controls.Add(this.btnSaveFile);
base.Controls.Add(this.txtDecryptedText);
base.Controls.Add(this.label3);
base.Controls.Add(this.label2);
base.Controls.Add(this.label1);
base.Controls.Add(this.txtCipherText);
base.Controls.Add(this.txtClearText);
base.Controls.Add(this.btnDecrypt);
base.Controls.Add(this.btnEncrypt);
base.Icon = (Icon) manager.GetObject("$this.Icon");
base.Name = "frmMain";
this.Text = "Sdl Creator by \x00a9Hyperlink";
((ISupportInitialize) this.error).EndInit();
((ISupportInitialize) this.pictureBox1).EndInit();
base.ResumeLayout(false);
base.PerformLayout();
}
private void InitObjects()
{
this._fileName = string.Empty;
}
private void LoadFileContent()
{
try
{
TextReader reader = new StreamReader(this._fileName);
try
{
this.txtFileContent.Text = reader.ReadToEnd();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
finally
{
reader.Close();
this.StartMonitorization();
}
}
catch (FileNotFoundException)
{
MessageBox.Show("Sorry, the file does not exist or it have been moved.");
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Sorry, you lack sufficient privileges.");
}
catch (Exception exception2)
{
MessageBox.Show(exception2.Message);
}
}
private void ResetUiContent()
{
this.txtFileContent.Text = string.Empty;
this._fileName = string.Empty;
}
private void SaveFileContent()
{
try
{
TextWriter writer = File.CreateText(this._fileName);
try
{
writer.Write(this.txtFileContent.Text);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
finally
{
writer.Close();
this.StartMonitorization();
}
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Fail. You lack sufficient privileges.");
}
catch (Exception exception2)
{
MessageBox.Show(exception2.Message);
}
}
private void StartMonitorization()
{
FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(this._fileName), Path.GetFileName(this._fileName));
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
watcher.IncludeSubdirectories = false;
this._fileMonitor = watcher;
this._fileMonitor.Changed += new FileSystemEventHandler(this.FileMonitor_OnChanged);
this._fileMonitor.Created += new FileSystemEventHandler(this.FileMonitor_OnChanged);
this._fileMonitor.Deleted += new FileSystemEventHandler(this.FileMonitor_OnDeleted);
this._fileMonitor.Renamed += new RenamedEventHandler(this.FileMonitor_OnRenamed);
this._fileMonitor.EnableRaisingEvents = true;
}
private void txtCipherText_TextChanged(object sender, EventArgs e)
{
}
private void txtClearText_TextChanged(object sender, EventArgs e)
{
}
// Nested Types
public delegate void LoadContentCallback();
}
Program.cs
Code:
internal static class Program
{
// Methods
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
}
}