private void btnDeleteFile_Click(object sender, EventArgs e) { if (lvFiles.SelectedItems.Count == 0) { return; } string fileName = lvFiles.SelectedItems[0].Text; CryptoServiceClient cloudProxy = new CryptoServiceClient(); bool deleteSuccessfull = cloudProxy.DeleteFile(fileName); if (deleteSuccessfull) { MessageBox.Show("File successfully deleted.", "Delete successfull", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error while deleting file.", "Delete error", MessageBoxButtons.OK, MessageBoxIcon.Error); } cloudProxy.Close(); showCloudFiles(); }
private void btnCryptFile_Click(object sender, EventArgs e) { if (fileForCryptPath.Equals("")) { MessageBox.Show("File isn't selected!", "Missing file!", MessageBoxButtons.OK, MessageBoxIcon.Error); lblFileCryptedSaved.Visible = false; return; } byte[] file = null; byte[] fileKey = Encoding.UTF8.GetBytes(generated256Key); byte[] randomKey = Encoding.UTF8.GetBytes(randomed256Key); if (generated256Key.Equals("") || randomed256Key.Equals("")) { MessageBox.Show("Key isn't generated", "Missing key!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } file = File.ReadAllBytes(fileForCryptPath); Dictionary <string, byte[]> properties = new Dictionary <string, byte[]>(); properties.Add("alphabet256", fileKey); properties.Add("alphabet256Key", randomKey); simpleSubstitutionAlgorithm.SetAlgorithmProperties(properties); byte[] cryptedFile = simpleSubstitutionAlgorithm.Crypt(file); File.WriteAllBytes(@".\\Crypted\\" + fileForCryptName + fileExtension, cryptedFile); if (cxbSaveToCloud.Checked) { var cloudProxy = new CryptoServiceClient(); using (var stream = new FileStream(@".\\Crypted\\" + fileForCryptName + fileExtension, FileMode.Open, FileAccess.Read)) { bool resultOfUpload = cloudProxy.UploadFile(fileForCryptName + fileExtension, stream); if (resultOfUpload == true) { MessageBox.Show("File uploaded to cloud!", "Successfull upload!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was error while trying to upload file!", "Error while uploading!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } cloudProxy.Close(); } lblFileCryptedSaved.Visible = true; lblFileCryptedSaved.Text = "File crypted!"; }
private void btnCryptFile_Click(object sender, EventArgs e) { if (fileForCryptPath.Equals("")) { MessageBox.Show("File isn't selected!", "Missing file!", MessageBoxButtons.OK, MessageBoxIcon.Error); lblFileCryptedSaved.Visible = false; return; } byte[] file = null; if (txbFileKey.Text.Equals("")) { MessageBox.Show("Key isn't generated", "Missing key!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } file = File.ReadAllBytes(fileForCryptPath); byte[] key = Encoding.UTF8.GetBytes(txbFileKey.Text); xxtea.SetKey(key); byte[] cryptedFile = xxtea.Crypt(file); File.WriteAllBytes(@".\\Crypted\\" + fileForCryptName + fileExtension, cryptedFile); if (cxbSaveToCloud.Checked) { var cloudProxy = new CryptoServiceClient(); using (var stream = new FileStream(@".\\Crypted\\" + fileForCryptName + fileExtension, FileMode.Open, FileAccess.Read)) { bool resultOfUpload = cloudProxy.UploadFile(fileForCryptName + fileExtension, stream); if (resultOfUpload == true) { MessageBox.Show("File uploaded to cloud!", "Successfull upload!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was error while trying to upload file!", "Error while uploading!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } cloudProxy.Close(); } lblFileCryptedSaved.Visible = true; lblFileCryptedSaved.Text = "File crypted!"; }
private void btnCryptFile_Click(object sender, EventArgs e) { if (fileForHashPath.Equals("")) { MessageBox.Show("File isn't selected!", "Missing file!", MessageBoxButtons.OK, MessageBoxIcon.Error); lblFileCryptedSaved.Visible = false; return; } byte[] file = null; file = File.ReadAllBytes(fileForHashPath); byte[] cryptedFile = sha2Algorithm.Crypt(file); string hashStr = ""; for (int i = 0; i < 32; i++) { hashStr += string.Format("{0:X2}", cryptedFile[i]); } File.WriteAllText(@".\\Crypted\\" + fileForHashName + fileExtension, hashStr); if (cxbSaveToCloud.Checked) { var cloudProxy = new CryptoServiceClient(); using (var stream = new FileStream(@".\\Crypted\\" + fileForHashName + fileExtension, FileMode.Open, FileAccess.Read)) { bool resultOfUpload = cloudProxy.UploadFile(fileForHashName + fileExtension, stream); if (resultOfUpload == true) { MessageBox.Show("File uploaded to cloud!", "Successfull upload!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was error while trying to upload file!", "Error while uploading!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } cloudProxy.Close(); } lblFileCryptedSaved.Visible = true; lblFileCryptedSaved.Text = "File hashed!"; }
private void btnKriptujFile_Click(object sender, EventArgs e) { if (fileForCryptPath.Equals("")) { MessageBox.Show("File isn't selected!", "Missing file!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } byte[] file = null; file = File.ReadAllBytes(fileForCryptPath); byte[] cryptedFile = algorithm.Crypt(file); File.WriteAllBytes(@".\\Crypted\\" + fileForCryptName + fileExtension, cryptedFile); if (checkCloud.Checked) { var cloudProxy = new CryptoServiceClient(); using (var stream = new FileStream(@".\\Crypted\\" + fileForCryptName + fileExtension, FileMode.Open, FileAccess.Read)) { bool resultOfUpload = cloudProxy.UploadFile(fileForCryptName + fileExtension, stream); if (resultOfUpload == true) { MessageBox.Show("File uploaded to cloud!", "Successfull upload!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was error while trying to upload file!", "Error while uploading!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } cloudProxy.Close(); } }
private void btnDownloadFile_Click(object sender, EventArgs e) { if (lvFiles.SelectedItems.Count == 0) { return; } string localFilePath = ""; string localFileName = lvFiles.SelectedItems[0].Text; int blockSize = 2048; CryptoServiceClient cloudProxy = new CryptoServiceClient(); Stream inputStream = cloudProxy.DownloadFile(ref localFileName); string fileExtension = Path.GetExtension(localFileName); using (SaveFileDialog sf = new SaveFileDialog()) { sf.FileName = localFileName; sf.Filter = "(*" + fileExtension + ")|" + fileExtension; if (sf.ShowDialog() == DialogResult.OK) { localFilePath = sf.FileName; } else { return; } } using (FileStream writeStream = new FileStream(localFilePath, FileMode.Create, FileAccess.Write)) { byte[] buffer = new byte[blockSize]; do { var bytesRead = inputStream.Read(buffer, 0, buffer.Length); if (bytesRead == 0) { break; } //Then it's last block if (bytesRead < blockSize) { var temp = new byte[bytesRead]; Array.Copy(buffer, temp, bytesRead); buffer = temp; } writeStream.Write(buffer, 0, buffer.Length); } while (true); writeStream.Close(); } if (File.Exists(localFilePath)) { MessageBox.Show("File downloaded.", "Downloaded successfull", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error while downloading file.", "Downloading error", MessageBoxButtons.OK, MessageBoxIcon.Error); } inputStream.Dispose(); cloudProxy.Close(); }