private void buttonEncFile_Click(object sender, EventArgs e) { string protect = Crypt.Decrypt(_protect.protect, userName + mac, mac + userName, "SHA1", 2, "32CRYPTODATA0117", 256); string key = Crypt.Decrypt(_key.data, userName, mac, "SHA1", 2, "32CRYPTODATA0117", 256); try { if (protect == key) { var file = GetFileFormat(textBoxDir1.Text); var format = Crypt.Encrypt(file, key, mac, "SHA1", 2, "32CRYPTODATA0117", 256); GCHandle gch = GCHandle.Alloc(SecretKey.Key, GCHandleType.Pinned); CryptFile.EncryptFile(textBoxDir1.Text, format + ".jakecd", SecretKey); gch.Free(); MessageBox.Show("The file was encrypted!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); if (checkBoxDelete.Checked == true) { System.IO.File.Delete(textBoxDir1.Text); } } else { MessageBox.Show("There was a problem with the protection system. Data can not be decrypted!", "Protect", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } } catch { MessageBox.Show("There was a problem with the protection system. Data can not be decrypted!", "Protect", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } }
public FormFile() { SecretKey = CryptFile.GenerateKey(); _key = Key.GetKey(); _protect = Key.GetProtect(); InitializeComponent(); }
private void buttonDecFile_Click(object sender, EventArgs e) { string protect = Crypt.Decrypt(_protect.protect, userName + mac, mac + userName, "SHA1", 2, "32CRYPTODATA0117", 256); string key = Crypt.Decrypt(_key.data, userName, mac, "SHA1", 2, "32CRYPTODATA0117", 256); try { if (protect == key) { string name = System.IO.Path.GetFileNameWithoutExtension(textBoxDir2.Text); var format = Crypt.Decrypt(name, key, mac, "SHA1", 2, "32CRYPTODATA0117", 256); GCHandle gch = GCHandle.Alloc(SecretKey.Key, GCHandleType.Pinned); CryptFile.DecryptFile(textBoxDir2.Text, "decrypted" + "." + format, SecretKey); gch.Free(); MessageBox.Show("The file was decrypted!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was a problem with the protection system. Data can not be decrypted!", "Protect", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } } catch { MessageBox.Show("There was a problem with the protection system. Data can not be decrypted!", "Protect", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } }
private void buttonDec2_Click(object sender, EventArgs e) { string protect = Crypt.Decrypt(_protect.protect, userName + mac, mac + userName, "SHA1", 2, "32CRYPTODATA0117", 256); string key = Crypt.Decrypt(_key.data, userName, mac, "SHA1", 2, "32CRYPTODATA0117", 256); try { if (protect == key) { if (this.maskedPassword2.Text != "") { try { string name = System.IO.Path.GetFileNameWithoutExtension(textBoxDir22.Text); var format = Crypt.Decrypt(name, this.maskedPassword2.Text, "EncryptFile/zArCIyCzbJxWwDfkHVD3Acty62lT7in9L", "SHA1", 2, "32CRYPTODATA0117", 256); GCHandle gch = GCHandle.Alloc(SecretKey.Key, GCHandleType.Pinned); CryptFile.DecryptFile(textBoxDir22.Text, "decrypted" + "." + format, SecretKey); gch.Free(); MessageBox.Show("The file was decrypted!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Incorrect password!", "Ooops!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("You did not enter anything!", "Ooops!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("There was a problem with the protection system. Data can not be decrypted!", "Protect", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } } catch { MessageBox.Show("There was a problem with the protection system. Data can not be decrypted!", "Protect", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } }