private void settingsTsmi_Click(object sender, EventArgs e) { string[] data = { "Login", "Password" }; if (Forms.ChangeInfo(ref data) == DialogResult.OK) { string oldLog = accountSddb.Text; if (data[0] != "" || data[0] != "Login") { accountSddb.Text = data[0]; } else { data[0] = accountSddb.Text; } if (data[1] != "" || data[1] != "Password") { File.Delete(path); path = FileSystem.FolderPath + "/" + EncryptionSystem.EncodePathFile(data[0] + data[1]) + ".dat"; } else { foreach (var file in Directory.GetFiles(FileSystem.FolderPath)) { if (EncryptionSystem.EncodePathFile(file).Contains(oldLog)) { File.Delete(path); path = file.Replace(oldLog, data[0]); } } } } }
public static void Main() { ChaoticEncryption.EncryptionSystem ecs = new EncryptionSystem(); Byte[] plT = new Byte[10] { 1,2,3,4,5,6,7,8,9,10 }; ecs.Encrypt(ref plT, out plT); ecs.Decrypt(ref plT, out plT); int a = 0; }
private void DecodeAll() { accounts = FileSystem.BinaryDeserialize(path) as List <Account>; if (accounts == null) { return; } foreach (Account account in accounts) { account.WebSite = EncryptionSystem.Decode(account.WebSite); account.Login = EncryptionSystem.Decode(account.Login); account.Password = EncryptionSystem.Decode(account.Password); } }
private void EncodeAll() { if (accounts == null) { return; } foreach (Account account in accounts) { account.WebSite = EncryptionSystem.Encode(account.WebSite); account.Login = EncryptionSystem.Encode(account.Login); account.Password = EncryptionSystem.Encode(account.Password); } FileSystem.BinarySerialize(accounts, path); File.SetAttributes(path, FileAttributes.Hidden); }
private void createAccountBtn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (ValidSystem.IsNotEmpty(logProblemLbl, loginTb.Text, passwordTb.Text)) { foreach (var file in Directory.GetFiles(FileSystem.FolderPath)) { if (EncryptionSystem.EncodePathFile(file).Contains(loginTb.Text)) { logProblemLbl.Text = "Account with similar login already exist."; return; } } File.Create(FileSystem.FolderPath + "/" + EncryptionSystem.EncodePathFile(loginTb.Text + passwordTb.Text) + ".dat"); File.SetAttributes(FileSystem.FolderPath + "/" + EncryptionSystem.EncodePathFile(loginTb.Text + passwordTb.Text) + ".dat", FileAttributes.Hidden); logInBtn_Click(sender, e); } }
private void logInBtn_Click(object sender, EventArgs e) { if (ValidSystem.IsNotEmpty(logProblemLbl, loginTb.Text, passwordTb.Text)) { if (File.Exists(FileSystem.FolderPath + "/" + EncryptionSystem.EncodePathFile(loginTb.Text + passwordTb.Text) + ".dat")) { this.Hide(); main.Login(loginTb.Text, FileSystem.FolderPath + "/" + EncryptionSystem.EncodePathFile(loginTb.Text + passwordTb.Text) + ".dat"); main.Show(); loginTb.Focus(); loginTb.Text = ""; passwordTb.Text = ""; logProblemLbl.Text = ""; } else { logProblemLbl.Text = "Your input is failed or this account is not exist. You can create a new account by clicking the button below."; passwordTb.Text = ""; } } }
public void WorkAsync(BackgroundWorker worker, DoWorkEventArgs e) { worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; ChaoticEncryption.Builder ceb = new ChaoticEncryption.Builder(); ceb.SetNcmParams(a, b, X0_ncm); ceb.SetWheelSwitchParams(r, X0_ws, Encoding.UTF8.GetBytes(Ke)); Byte[] buffer = new Byte[2048]; Byte[] cipherBlock = null; FileStream inStream = null; FileStream outStream = null; BinaryReader binaryReader = null; BinaryWriter binaryWriter = null; int length = 0; FileInfo fi = new FileInfo(filepath); long totalSize = fi.Length; long completedSize = 0; try { inStream = new FileStream(filepath, FileMode.Open); binaryReader = new BinaryReader(inStream); if (workType == EncryptionWorkType.DECRYPT) { // Set FileName // Read byteCount of filename String SaveName; // Filename to save int filenameLength = binaryReader.ReadInt32(); SaveName = Encoding.UTF8.GetString(binaryReader.ReadBytes(filenameLength)); SavePath = String.Concat(SavePath, '\\', SaveName); fi = new FileInfo(SavePath); if (fi.Exists) { SavePath = String.Concat(SavePath.Remove(SavePath.LastIndexOf('.')), "_Copy", SavePath.Substring(SavePath.LastIndexOf('.'))); } } outStream = new FileStream(SavePath, FileMode.OpenOrCreate); binaryWriter = new BinaryWriter(outStream); if (workType == EncryptionWorkType.ENCRYPT) { // Write fileName in the output. First 4 Byte(int) is the byteCount of fileName. Then fileName in Bytes follows. String filename; filename = filepath.Substring(filepath.LastIndexOf('\\') + 1); Byte[] fileNameInBytes = Encoding.UTF8.GetBytes(filename); int size = fileNameInBytes.Length; binaryWriter.Write(size); binaryWriter.Write(fileNameInBytes); } while ((length = binaryReader.Read(buffer, 0, 2048)) > 0) { encryptionSystem = ceb.CreateSystem(buffer); if (workType == EncryptionWorkType.ENCRYPT) encryptionSystem.Encrypt(ref buffer, out cipherBlock); else encryptionSystem.Decrypt(ref buffer, out cipherBlock); binaryWriter.Write(cipherBlock, 0, length); completedSize += length; worker.ReportProgress((int)(100 * completedSize / totalSize)); } } catch (Exception exception) { System.Windows.MessageBox.Show("Error occurs when reading file!\n" + exception.Message); worker.CancelAsync(); } if (binaryReader != null) binaryReader.Close(); if (inStream != null) inStream.Close(); if (binaryWriter != null) binaryWriter.Close(); if (outStream != null) outStream.Close(); worker.ReportProgress(100); }