public static Img FromHashedFile(string str, string stringKey, CallBackDelegate callBack, LogDelegate Log) { string newStr = null; Log("Parsing key.."); List <int> key = Img.ParseKey(stringKey, callBack); Log("Key parsed successfully..\nUnhashing the file using the key.."); newStr = Img.Unhash(str, key, callBack); Log("Done"); Img img = Img.FromBase64String(newStr, false); img.IsHashed = true; img.HashedBase64String = newStr; return(img); }
private void ChooseImage(object sender, EventArgs e) { if (chooseImageDialog.ShowDialog() == DialogResult.OK) { Log("Loading file.."); Thread InitClassThread = new Thread(() => { try { Img = new Img(Image.FromFile(chooseImageDialog.FileName)); pictureBox1.Image = Img.Image; } catch (Exception) { MessageBox.Show("An error has occured. Make sure that you've selected valid file and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); InitClassThread.Start(); Log("File loaded successfully.."); } }
private void button4_Click(object sender, EventArgs e) { string str = null; string key = null; if (openFileDialog.ShowDialog() == DialogResult.OK) { Log("Loading file.."); using (StreamReader sr = new StreamReader(openFileDialog.FileName)) { str = sr.ReadToEnd(); } Log("File loaded..\nLoading key.."); if (openKeyDialog.ShowDialog() == DialogResult.OK) { Thread th = new Thread(() => { try { using (StreamReader sr = new StreamReader(openKeyDialog.FileName)) { key = sr.ReadToEnd(); } Img = Img.FromHashedFile(str, key, UpdateProgressBar, Log); pictureBox1.Image = Img.Image; } catch (Exception) { MessageBox.Show("An error has occured. Make sure that you've selected valid file type and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Log("", false); } }); th.Start(); return; } Log("Something went wrong..\nAborting.."); } }
private void OpenFile(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { Log("Loading file.."); Thread LoadFileThread = new Thread(() => { try { Img = Img.FromBase64String(openFileDialog.FileName, true); Log("File loaded successfully.."); pictureBox1.Image = Img.Image; } catch (Exception) { MessageBox.Show("An error has occured. Make sure that you've selected valid file type and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Log("", false); } }); LoadFileThread.Start(); } }
// Loading from Base64 string. Since Base64 string and file path are both the same type, method cannot be overloaded public static Img FromBase64String(string str, bool filePath) { byte[] bArr = null; switch (filePath) { case false: { bArr = Convert.FromBase64String(str); break; } case true: { using (StreamReader sr = new StreamReader(str)) { string tempStr = sr.ReadToEnd(); bArr = Convert.FromBase64String(tempStr); } break; } } return(Img.FromByteArray(bArr)); }